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 |
|
chakrinn
Starting Member
3 Posts |
Posted - 2009-10-28 : 08:07:49
|
| Hi,I am struggling to get the week number and week day of the particular day. I know we can use Datepart function which is available in sql server 2008 to display the week number of the given date. but my situation is different. for example Datepart(wk,'2009-12-30') gives 53 weeksDatepart(wk,'2010-01-02') gives 1. but I wanted to display it as 54.whenever the year is changing I need to add these week number to the previous year one. How to generated it dynamically.Date ------ weekNumber----------------------------12/21/2009 --> 5212/23/2009 --> 5212/30/2009 --> 531/2/2010 --> 1 Here I wanted to display as 54.... Thanks in advance |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-28 : 08:55:56
|
| Like thisselect datepart(wk,'1/2/2010 ')+case when year('1/2/2010')<>year(getdate()) then datepart(wk,'12/31/'+datename(year,getdate())) else 0 endMadhivananFailing to plan is Planning to fail |
 |
|
|
chakrinn
Starting Member
3 Posts |
Posted - 2009-10-28 : 09:11:21
|
| Thanks Mashivanan. How can we get the first day of the week in the same query. say in the above example 12/21/2009 returns week number as 52, the start day for this week is 12/20/2009. and for 1/2/2010 it returns week number as 54 according to your query, and need to display the starting date for this week is 12/27/2009. How can we do this. Thanks.. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-10-28 : 11:55:27
|
| seems you want DATEDIFF, not DATEPART |
 |
|
|
chakrinn
Starting Member
3 Posts |
Posted - 2009-10-29 : 03:17:25
|
| what ever function we use but finally need the output of how I am requested.. |
 |
|
|
|
|
|