Finding First Sunday of a Month

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 456

--first sunday of a month
DECLARE @MonthNumber int = 7
SELECT DATEADD(dd,(DATEDIFF(dd,0,DATEADD(mm,@MonthNumber-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)))/7 * 7 )+6,0)


OUTPUT:
2014-07-06 00:00:00.000

Comments or Responses

Login to post response