Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get date of previous Sunday

Status
Not open for further replies.

JayKusch

MIS
Oct 30, 2001
3,199
US
Morning,

I know I am close BUT I still can't get this code snippette to return the date of last sunday (as in 1/9/2011 - format of date does not matter).

Here is what I have so far (borrowed from a web page):

Code:
DECLARE	@LastSundayNight DateTime
SET	@LastSundayNight	= GetDate()

SELECT	CASE	WHEN	DATENAME(dw,@LastFridayNight) ='Sunday' AND CONVERT(VarChar,@LastSundayNight,108) > '22:00:00' 
				THEN	CONVERT(VarChar,@LastSundayNight,1) 
				ELSE	CONVERT(VarChar,DATEADD(d,-((datepart(dw,@LastSundayNight)+@@DATEFIRST)%7+1),@LastSundayNight),1) 
				END		+ ' 22:00:00'

Thanks!

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top