Loading ...

Get first and last day of month in sql | CodeAsp.Net

Get first and last day of month in sql

 /5
0 (0votes)

In this blog I will explain how to get first and last day of month in sql. Below is the code snippet.

DECLARE @date DATETIME

SET @date = '20090809'

Select DATEADD(m, DATEDIFF(m, 0, @date), 0) AS FirstDayOfMonth,

DATEADD(mm, DATEDIFF(mm, 0, @date)+1, -1) AS LastDayOfMonth

--Output

FirstDayOfMonth LastDayOfMonth

----------------------- -----------------------

2009-08-01 00:00:00.000 2009-08-31 00:00:00.000

 

Happy Reading.!

 

 

Comments (no comments yet)

Top Posts