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 2000 Forums
 SQL Server Development (2000)
 Correct Week No. of Date

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

Posted - 2006-02-06 : 04:20:15
quote:
How do I get the correct week number of a date.

What do you mean correct week number ?
Also refer to here
ISO Year Week Day of Week Function] or
ISO Week of Year Function

----------------------------------
'KH'


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-06 : 04:24:21
You should use DatePart

Select Datepart(ww,getdate()) as weekno

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-06 : 04:43:02
quote:
Originally posted by madhivanan

You should use DatePart

Select Datepart(ww,getdate()) as weekno

Madhivanan

Failing to plan is Planning to fail


ha ha did not even noticed the use of datediff. i must be going blind

----------------------------------
'KH'


Go to Top of Page

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

Madhivanan

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

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'


Go to Top of Page

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
Go to Top of Page
   

- Advertisement -