Queries Related to Dates-(SQl Server)

Posted by Chvrsri under Sql Server category on | Points: 40 | Views : 2184
HI all,

Now iam going to give you the queries which are intended to give the Dates as following

To Find FirstDay of a Week

select DateAdd(d,1 - DATEPART(w,'2015-4-19'),'2015-4-19')

To Find LastDay of a Week

select DateAdd(d,7 - DATEPART(w,'2015-4-19'),'2015-4-19')

Note : From here replace @date with your choice of date in the format of 'yyyy-mm-dd'

To Find No. OF Days In a Month

Select DATEDIFF(d,@date,DATEADD(m,1,@date))

To Find FirstDay of a Month

Select DATEDIFF(d,@date,DATEADD(m,1,@date))

Cheers !!!

To Find LastDay Of a Month

select DATEADD(d,DATEDIFF(d,@date,DATEADD(m,1,@date)) - day(@date),@date)

Comments or Responses

Login to post response