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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 12 weeks ago

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-03-06 : 06:24:39
hi,
how can I get the first day of the week 12 weeks ago ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-06 : 06:31:42
DATEADD(d,(-1) * DATEPART(dw,GETDATE()),DATEADD(wk,-12,GETDATE()))

also remember to SET DATEFIRST to your first day of the week.
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-03-06 : 07:50:50
set datefirst ?
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-03-06 : 07:55:21
also , this seems to go back 15 weeks !? very strange
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-06 : 07:59:48
15 weeks? how?
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-03-06 : 08:10:00
not sure, but it shows the 08 dec 07..
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-06 : 08:19:27
This is the 10th week of 2008, so 12 weeks ago is in Dec 2007




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-06 : 08:19:33
Thats almost correct. Counting backwards you will get thursdays as

28Feb2008 1
21Feb2008 2
14Feb2008 3
07Feb2008 4
31Jan2008 5
24Jan2008 6
17Jan2008 7
10Jan2008 8
03Jan2008 9
27Dec2007 10
20Dec2007 11
13Dec2007 12

now you have to find out starting day (Sunday) of week having 13Dec2007 which is 9 Dec...so probably you need add 1 to earlier result. i.e

DATEADD(d,(-1) * (DATEPART(dw,GETDATE())-1),DATEADD(wk,-12,GETDATE()))


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-06 : 08:21:59
quote:
Originally posted by dataguru1971

This is the 10th week of 2008, so 12 weeks ago is in Dec 2008




Poor planning on your part does not constitute an emergency on my part.




Did you meant Dec 2007?
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-06 : 08:47:26
quote:
Originally posted by visakh16

quote:
Originally posted by dataguru1971

This is the 10th week of 2008, so 12 weeks ago is in Dec 2008




Poor planning on your part does not constitute an emergency on my part.




Did you meant Dec 2007?



LOL..absolutely did mean 2007....or it was my attempt to be as confused as everyone else around here.



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-03-06 : 08:53:15
ok, thank you very much !
Go to Top of Page
   

- Advertisement -