Re: Week to date function - Mailing list pgsql-sql

From Jorge Godoy
Subject Re: Week to date function
Date
Msg-id m2w175c742d1003271108p773ebaa7y4fedf008762ed12c@mail.gmail.com
Whole thread Raw
In response to Re: Week to date function  (Ireneusz Pluta <ipluta@wp.pl>)
Responses Re: Week to date function  (Ireneusz Pluta <ipluta@wp.pl>)
List pgsql-sql
Are you sure?


Week dates

YYYY-WwworYYYYWww
YYYY-Www-DorYYYYWwwD

Week date representations are in the format as shown in the box to the right. [YYYY] indicates the ISO week-numbering year which is slightly different to the calendar year (see below). [Www] is the week number prefixed by the letter 'W', from W01 through W53. [D] is the weekday number, from 1 through 7, beginning with Monday and ending with Sunday. This form is popular in the manufacturing industries.

There are mutually equivalent descriptions of week 01:

      • the week with the year's first Thursday in it (the formal ISO definition),
      • the week with 4 January in it,
      • the first week with the majority (four or more) of its days in the starting year, and
      • the week starting with the Monday in the period 29 December – 4 January.

If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.

The week number can be described by counting the Thursdays: week 12 contains the 12th Thursday of the year.


In 2009, January 1st. happened on a Thursday.

As Jan 1st, 2010 happened on a Friday, it was on week 53 of 2009.




--
Jorge Godoy     <jgodoy@gmail.com>


On Fri, Mar 26, 2010 at 07:48, Ireneusz Pluta <ipluta@wp.pl> wrote:
 
Yes, much smarter.
However, would give the same results on (year=2009, week=53) and (year=2010, week=1). In fact, 2009 did not have week 53.
I wrapped it into a function with additional isoyear check and now seems OK.

Thanks

pgsql-sql by date:

Previous
From: Ireneusz Pluta
Date:
Subject: Re: Week to date function
Next
From: Ireneusz Pluta
Date:
Subject: Re: Week to date function