Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL first Sunday and last Sunday

Author  Topic 

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2011-07-20 : 03:48:16
Hi, I had a stored procedure that accept one date. Then I want to get last Sunday of the date. For example, I pass in '2011-01-01'. The previous Sunday of '2011-01-01' should be '2010-12-26'...

How can I use SQL to get this?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-07-20 : 04:33:31
Previous Sunday:
select dateadd(day, 1 - datepart(dw, getdate()), getdate())

Just change getdate() with your date field.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-20 : 07:22:02
see
http://visakhm.blogspot.com/2010/02/find-out-particular-occurance-of.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -