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 |
Brittney10
Posting Yak Master
154 Posts |
Posted - 2011-12-09 : 10:23:45
|
I'm trying to get the week number, but for some reason it's showing 01/01/2011 as Week 1 (this is correct), but 01/02/2011 - 01/06/2011 is showing as Week 2???? I'm using Datepart(Week, MyDate). Any input would be greatly appreciated. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-09 : 10:27:12
|
thats correct. see calendar 2nd week starts @ Jan 2------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Brittney10
Posting Yak Master
154 Posts |
Posted - 2011-12-09 : 15:00:06
|
Well that does make sense. Do you also know how i might be able to capture only the previous 4 weeks only? |
 |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2011-12-09 : 15:42:49
|
quote: Originally posted by Brittney10 Well that does make sense. Do you also know how i might be able to capture only the previous 4 weeks only?
SELECT * FROM yourtableWHERE mydate >= dateadd(wk,-4,dateadd(dd, datediff(dd, 0, getdate()), 0)) |
 |
|
Brittney10
Posting Yak Master
154 Posts |
Posted - 2011-12-09 : 16:08:32
|
Sweet! That worked!quote: Originally posted by vijayisonly
quote: Originally posted by Brittney10 Well that does make sense. Do you also know how i might be able to capture only the previous 4 weeks only?
SELECT * FROM yourtableWHERE mydate >= dateadd(wk,-4,dateadd(dd, datediff(dd, 0, getdate()), 0))
|
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-10 : 07:55:22
|
previous four week means absolute 4 weeks or that relative to todays date?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|