Re: Week to date function
От | Jorge Godoy |
---|---|
Тема | Re: Week to date function |
Дата | |
Msg-id | m2w175c742d1003271108p773ebaa7y4fedf008762ed12c@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Week to date function (Ireneusz Pluta <ipluta@wp.pl>) |
Ответы |
Re: Week to date function
|
Список | pgsql-sql |
Week dates
Main article: 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.
--
Jorge Godoy <jgodoy@gmail.com>
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 по дате отправления: