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)
 Calculate week commencing date

Author  Topic 

ams006
Yak Posting Veteran

55 Posts

Posted - 2009-12-02 : 08:18:36
Hi All,

I have a date field e.g 02/12/2009 and need to be able to calculate the Monday's date of the week which the date field falls into i.e. I need to have returned to me 30/11/2009 which is the Monday of that week.

Any help will be appreciated.

ams006

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-02 : 08:40:27

declare @t datetime
set @t=convert(datetime,'02/12/2009',103)
select dateadd(week,datediff(week,0,@t),0)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ams006
Yak Posting Veteran

55 Posts

Posted - 2009-12-02 : 08:59:01
Thanks for your help madhivanan......nice one!
Go to Top of Page

vikky
Yak Posting Veteran

54 Posts

Posted - 2009-12-03 : 03:58:34
HI,

this one also helps u.

declare @date datetime
select @date = convert(datetime,'12/12/2009',103)

select dateadd(d,-datepart(dw,@date)+2,@date)

Thanks,
vikky.
Go to Top of Page
   

- Advertisement -