Quantcast
Channel: SQL Server Teacher
Viewing all articles
Browse latest Browse all 26

How to Get the First and Last Day of any Month in SQL Server

$
0
0

Hi,

 

Use to the below query to get the first and last day of any month in SQL Server.

 

DECLARE @Month int, @Year int, @First datetime, @Last datetime

set @Month = 4

set @Year = 2012

select @First =DATEADD(month,@Month-1,DATEADD(year,@Year-1900,0))

select @Last =DATEADD(day,-1,DATEADD(month,@Month,DATEADD(year,@Year-1900,0)))

select @First as'First Day',@Last as'Last Day'

 

Regards,

Selvaraj.


Viewing all articles
Browse latest Browse all 26

Trending Articles