Re: ISO weeknumbers

From: Mark D Powell <Mark.Powell_at_eds.com>
Date: Wed, 7 Jan 2009 09:58:16 -0800 (PST)
Message-ID: <5c262553-c608-431e-883c-3329ce537c85_at_p2g2000prn.googlegroups.com>



On Jan 6, 4:06 pm, Shakespeare <what..._at_xs4all.nl> wrote:
> Mark D Powell schreef:
>
>
>
>
>
> > 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 --
>
> Mark,
>
> this partly proves my point that week 1 always contains January 4th.
> Thanks for that!
>
> (except in 2001, when it was in week 13????)
>
> You must have some errors in your script though, like this value:
>
>  > -- 0103
>  > 01
>  > --
>  > 09
>
> which states that January 3rd was in week 9 in 2001
>
> There are more of those errors in 2001....
>
> Happy 2009!
> Shakespeare- Hide quoted text -
>
> - Show quoted text -

Typo in the date for that entry. The equilivent column in all the years is probably wrong, but since the point was just how the days tend to fall and how often we have 53 weeks I will not waste bandwidth by reposting. (The necessary SQL being partially posted)

Thank you for actually reading the output. I still do not know how I missed such an obvious error.

HTH -- Mark D Powell -- Received on Wed Jan 07 2009 - 11:58:16 CST

Original text of this message