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 |
|
swatib
Posting Yak Master
173 Posts |
Posted - 2006-02-06 : 02:21:26
|
How do I get the correct week number of a date.I thought that its simple using Datediff(ww,<ur date>) but it is not many times it gives wrong value..Surprising!!!!Even I've read same doubts others are facing for this.Please tell me the right way.......Njoy Life  |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-06 : 04:24:21
|
| You should use DatePartSelect Datepart(ww,getdate()) as weeknoMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-06 : 04:43:02
|
quote: Originally posted by madhivanan You should use DatePartSelect Datepart(ww,getdate()) as weeknoMadhivananFailing to plan is Planning to fail
ha ha did not even noticed the use of datediff. i must be going blind ----------------------------------'KH' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-06 : 06:50:00
|
>> i must be going blind No. You seem to be fast as usual MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-06 : 07:07:52
|
>> No. You seem to be fast as usual Maybe need to slow down a bit to read the posted question carefully ----------------------------------'KH' |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-02-06 : 09:53:15
|
quote: Originally posted by swatib How do I get the correct week number of a date.I thought that its simple using Datediff(ww,<ur date>) but it is not many times it gives wrong value..Surprising!!!!Even I've read same doubts others are facing for this.Please tell me the right way.......Njoy Life 
You really need to tell us what your definition is of "correct week number of a date" This is something that varies from one organization to the next. We need to know what you would consider the first date of the year for the purpose of calculating the week, and what you use for the first day of the week.There are international standards (ISO 8601) for week numbers, but unless your organization uses them, they may not be useful for you. If they do follow the ISO standards , then the functions that khtan posted links for should work for you.CODO ERGO SUM |
 |
|
|
|
|
|
|
|