Find first sunday of the month in SQL Server

02 Aug 2013    by: Sameer Das

It required check Sunday when you generate installment schedule using Store Procedure.


declare @sun datetime
set @sun=DATEADD(Month, DATEDIFF(Month, 0, GETDATE()) + 0, 0) +
6 - (DATEPART(Weekday,DATEADD(Month,DATEDIFF(Month,0, GETDATE()) + 0, 0))
+ @@DateFirst + 5) % 7

print @sun

Tags:

Leave a Reply

Be the First to Comment!

Notify of
avatar