Re: ISO weeknumbers
Date: Tue, 6 Jan 2009 12:13:51 -0800 (PST)
Message-ID: <dda85c72-f634-4f91-a227-01f351e12ca2_at_m15g2000vbp.googlegroups.com>
On Jan 6, 4:13 am, sybrandb <sybra..._at_gmail.com> wrote:
> On 5 jan, 21:41, "Terry Dykstra" <tddyks..._at_forestoil.ca> wrote:
>
>
>
>
>
> > The IW format string returns the ISO week number
>
> > IW
> > No
> > Week of year (1-52 or 1-53) based on the ISO standard.
>
> > I'm confused by this. When would you get week 53? For example, when
> > running this against the last week of 2008 (using 9.2.0.7 SE) , it switches
> > from week 52 to week 1 while still in December.
>
> > select to_char(to_date('20081228','yyyymmdd') ,'IW') from dual;> 52
>
> > select to_char(to_date('20081229','yyyymmdd') ,'IW') from dual;
>
> > > 01
>
> > --
> > Terry Dykstra
>
> Week 53 occurs about once in 4 years.
> This is why in the past have been hunting for a bug for 4 years.
> The bug only occurred in week 53, as the application could only handle
> 52-week years.
>
> --
> Sybrand Bakker
> Senior Oracle DBA- Hide quoted text -
>
> - Show quoted text -
I found this thread interesting and ran a little test. I displayed the week number for all years from 1990 - 2029 for dates of 1227 to 0104. From this it appears that a year has 53 weeks every 5 or 6 years. What really caught my eye was how often January 1 is part of the prior year.
- ISO Weeks in Year
- using SQL like
- select
- to_char(to_date('19900104','yyyymmdd') ,'IW') as "90"
- ,to_char(to_date('19910104','yyyymmdd') ,'IW') as "91"
- ,to_char(to_date('19920104','yyyymmdd') ,'IW') as "92"
- ,to_char(to_date('19930104','yyyymmdd') ,'IW') as "93"
- ... from dual
- 1227 always week 52 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 52 52 52 52 52 52 52 52 52 52 52 52 53 52 52 52 52 52
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52
- 1228 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 53 52 52 52 52 52 53 52 52 52 52 52 53 52 52 52 52 53
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 52 52 52 53 52 52 52 52 53 52 52 52 52 52 53 52 52 52
- 1229 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 53 52 52 52 52 01 53 52 52 52 52 01 53 52 52 52 01 53
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 52 52 01 53 52 52 52 52 53 52 52 52 52 01 53 52 52 52
- 1230 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 01 53 52 52 52 01 01 53 52 52 52 01 01 53 52 52 52 01 53
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 52 01 01 53 52 52 52 01 53 52 52 52 01 01 53 52 52 52
- 1231 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 01 01 53 52 52 52 01 01 53 52 52 01 01 01 53 52 52 01 01 53
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 52 52 01 01 01 53 52 52 01 01 53 52 52 52 01 01 53 52 52 01
- 0101 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 01 01 01 53 52 52 01 01 01 53 52 01 01 01 01 53 52 01 01 01
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 53 52 52 01 01 01 53 52 01 01 01 53 52 52 01 01 01 53 52 01
- 0102
90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 01 01 01 53 52 01 01 01 01 53 52 05 01 01 01 53 01 01 01 01
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 53 52 01 01 01 01 53 01 01 01 01 53 52 01 01 01 01 53 52 01
- 0103 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 01 01 01 53 01 01 01 01 01 53 01 09 01 01 01 01 01 01 01 01
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 53 01 01 01 01 01 53 01 01 01 01 53 01 01 01 01 01 53 01 01
- 0104 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 01 01 01 01 01 01 01 01 01 01 01 13 01 01 01 01 01 01 01 01
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
HTH -- Mark D Powell -- Received on Tue Jan 06 2009 - 14:13:51 CST