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
 General SQL Server Forums
 New to SQL Server Programming
 Need help with Week # of #

Author  Topic 

webduckie
Starting Member

1 Post

Posted - 2012-02-06 : 14:40:16
I have a start date of Feb 13, 2012 and end date of Apr 20, 2012 for a school schedule. The schedule is always 10 weeks and it runs three times a year. I need to determine what week I am in based on a date I enter and based on what the school start date is. If it is March 27 then I am in Week 7, if Feb 18 then Week 1, if Feb 19 then Week 2. Any suggestions?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-02-06 : 14:50:49
[code]DECLARE @date DATETIME, @startDate DATETIME;
SET @date = '20120327';
SET @startDate = '20120213';
SELECT 1+(1+DATEDIFF(dd,@startDate,@date))/7;[/code]
Go to Top of Page
   

- Advertisement -