Thread: To get a weeknumber of Date ina year


Permlink Replies: 4 - Pages: 1 - Last Post: Sep 1, 2008 2:31 AM Last Post By: user596543
vivekvm

Posts: 88
Registered: 07/06/06
To get a weeknumber of Date ina year
Posted: Jul 22, 2008 11:08 AM
Click to report abuse...   Click to reply to this thread Reply
hi
how we can findout the Wee Number of a Date in an year.

for example
week number 4/jan/2008 is 1
week number 28/jan/2008 is 52

like that for a given date how we get the weeknumber??

Thanks and regards
Vivek

Edgar Chupit

Posts: 23
Registered: 07/27/05
Re: To get a weeknumber of Date ina year
Posted: Jul 22, 2008 11:25 AM   in response to: vivekvm in response to: vivekvm
Click to report abuse...   Click to reply to this thread Reply
Hi,

You have to use IW format specifier in to_char function. Something like:

SQL> select to_char( date '2008-01-04', 'IW' ) from dual
2 /

TO_CHAR(DATE'2008-01-04','IW')

01
MYH

Posts: 761
Registered: 08/02/07
Re: To get a weeknumber of Date ina year
Posted: Jul 22, 2008 11:26 AM   in response to: vivekvm in response to: vivekvm
Click to report abuse...   Click to reply to this thread Reply
Hi,

You can use to_char function with the option 'w'
SQL> select to_char(to_date(sysdate),'w') from dual
SQL> /

T
-
4
Edgar Chupit

Posts: 23
Registered: 07/27/05
Re: To get a weeknumber of Date ina year
Posted: Jul 22, 2008 11:36 AM   in response to: MYH in response to: MYH
Click to report abuse...   Click to reply to this thread Reply
Basically, there are 3 to_char format models to get week number:

* W - week number in a month
* WW - week number in a year, week 1 starts at 1st of Jan
* IW - week number in a year, according to ISO standard - http://en.wikipedia.org/wiki/Week#Week_number
user596543

Posts: 125
Registered: 09/24/07
Re: To get a weeknumber of Date ina year
Posted: Sep 1, 2008 2:31 AM   in response to: vivekvm in response to: vivekvm
Click to report abuse...   Click to reply to this thread Reply
Hi All

Thank u very much for reply
other than 'IW' is there any other way to get week number...
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums