Re: Week to date function

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
To: Ireneusz Pluta <ipluta(at)wp(dot)pl>
Cc: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Week to date function
Date: 2010-03-27 18:08:53
Message-ID: m2w175c742d1003271108p773ebaa7y4fedf008762ed12c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Are you sure?

http://en.wikipedia.org/wiki/ISO_8601

Week dates

Main article: ISO week date <http://en.wikipedia.org/wiki/ISO_week_date>

*YYYY-Www* *or* *YYYYWww* *YYYY-Www-D* *or* *YYYYWwwD*

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(at)gmail(dot)com>

On Fri, Mar 26, 2010 at 07:48, Ireneusz Pluta <ipluta(at)wp(dot)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
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ireneusz Pluta 2010-03-27 20:22:18 Re: Week to date function
Previous Message Ireneusz Pluta 2010-03-26 11:47:13 Re: Week to date function