June 9, 2008 at 11:27 pm
Hi
I have a requirement that , i will be given a date and i want to find out the date of the weekend Saturday with reference to the given date. Can any one have any suggestion to do this. Thanks in advance.
Thanks
Nicsam
June 9, 2008 at 11:37 pm
IF (DATEPART(dw,'2008/06/14') IN (1,7))
begin
PRINT 'HOLIDAY'
enD
you can also use a variable instead of the date if you want.
"Keep Trying"
June 10, 2008 at 12:40 pm
declare @Date_in datetime -- input parameter
select @Date_in = getdate() -- or any other date
select dateadd(day, -1 * datepart(weekday, @date_in), @date_in) + 7
That will find the Saturday that follows any given date. You can use a datetime column, instead of a variable, too.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
June 10, 2008 at 1:01 pm
If you'd rather get away from DATEPART(weekday), (which is affected by the DATEFIRST setting on the server, do a simply math calc from a known Saturday:
select datediff(day,'19000106',getdate())%7
Anything with a value of 0 = Saturday, 1=Sunday, etc.....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply