Thread: BUG #3892: Invalid week determination

BUG #3892: Invalid week determination

From
"Roman"
Date:
The following bug has been logged online:

Bug reference:      3892
Logged by:          Roman
Email address:      rk@infren.com
PostgreSQL version: 8.1.4
Operating system:   FC6
Description:        Invalid week determination
Details:

Hello

Today is 2007-01-21.

select to_char(now(),'yyyyWW')

returns 200803, which is wrong(?)

When I set the date to 2007-01-22 I get 200804 , which is correct.

Is that ok ? Should it not be 200804 also for 2007-01-21 ?

Regards
Roman

I see in the doc: ( however it does not explain the case )

week
The number of the week of the year that the day is in. By definition (ISO
8601), the first week of a year contains January 4 of that year. (The
ISO-8601 week starts on Monday.) In other words, the first Thursday of a
year is in week 1 of that year. (for timestamp values only)

Because of this, it is possible for early January dates to be part of the
52nd or 53rd week of the previous year. For example, 2005-01-01 is part of
the 53rd week of year 2004, and 2006-01-01 is part of the 52nd week of year
2005.

Re: BUG #3892: Invalid week determination

From
Magne Mæhre
Date:
Roman wrote:>> I see in the doc: ( however it does not explain the case )>> week> The number of the week of the year
thatthe day is in. By definition (ISO> 8601), the first week of a year contains January 4 of that year. (The> ISO-8601
weekstarts on Monday.) In other words, the first Thursday of a> year is in week 1 of that year. (for timestamp values
only)>


It's actually in the doc for the to_char() function.  'WW' uses a week
definition where January 1st is in week 1.    If you use 'IW', you get
the ISO definition.

=> select to_char(now(),'yyyyIW'); to_char
--------- 200804
(1 row)


=> select extract(week from now()); date_part
-----------         4


--Magne