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.
Author |
Topic |
learntsql
524 Posts |
Posted - 2011-08-04 : 03:52:53
|
Hi All,I have a requirement to add "X" no. of weeks for latest date once i get that date i have get the date based on second parameter.The second parameter is weekname.for Eg:latestdate is 27-jul-2011add 1 week -->03-Aug-2011and second parameter is Sat'daynow i have to get the next sat'day day from here.TIA. |
|
learntsql
524 Posts |
Posted - 2011-08-04 : 06:05:41
|
Experts any idea plz....! |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-08-04 : 06:37:44
|
Look up DATEADD and DATEPART.And have some patience. We're all volunteers here, we all have our own jobs and our own problems and post in our spare time. Bumping your post after 2 hours is entirely unnecessary.--Gail ShawSQL Server MVP |
|
|
learntsql
524 Posts |
Posted - 2011-08-04 : 07:00:20
|
Hey I am sorry,I didnt mean that.anyhow i could manage it.Thanks for your cocern. |
|
|
lappin
Posting Yak Master
182 Posts |
Posted - 2011-08-04 : 07:29:29
|
I'm sure some-one could do a better way - but this works:Create Procedure getWkDay @DyName as varchar(10),@iNoWeeks as integerAS--Usage: exec getWkDay 'Saturday',1declare @iDy as integerdeclare @Today as date = getdate()declare @NewDt as datedeclare @increment as integerdeclare @StartDayNo as integer =datepart(dw,@Today)declare @DayDiff as integerset @NewDt =DATEADD(week,@iNoWeeks,@Today)SELECT @iDy = CASE @DyName WHEN 'Monday' THEN 1 WHEN 'Tuesday' THEN 2 WHEN 'Wednesday' THEN 3 WHEN 'Thursday' THEN 4 WHEN 'Friday' THEN 5 WHEN 'Saturday' THEN 6 WHEN 'Sunday' THEN 7 ELSE -99 END If @iDy>@StartDayNobeginset @DayDiff = ( @iDy - @StartDayNo )endIf @iDy<=@StartDayNobeginset @DayDiff = 7+ ( @iDy - @StartDayNo )endselect DATEADD(DD,@DayDiff, @NewDt) as NextDy |
|
|
|
|
|