Problems with to_char(created, 'WW')

Поиск
Список
Период
Сортировка
Искать

Problems with to_char(created, 'WW')

От:
Andreas Joseph Krogh <andreak@officenet.no>
Дата:
Hi.
I have the following schema in PostgreSQL-7.2.2:

CREATE TABLE session (session_id varchar(256) NOT NULL PRIMARY KEY,created timestamp DEFAULT 'now' NOT NULL,last_accessed timestamp NOT NULL,destroyed timestamp NOT NULL,username varchar -- Allow sessions from not logged in users
);

Now I run this query to extract the week numbers:

janerik=# select created, to_char(created, 'WW') as week from session WHERE
username IS NULL ORDER BY week;         created           | week 
----------------------------+------2002-09-24 11:23:21.206+02 | 392002-09-24 18:19:06.304+02 | 392002-09-25 10:50:27.139+02 | 392002-09-30 12:32:06.898+02 | 392002-10-01 16:26:41.122+02 | 402002-10-04 13:47:02.922+02 | 402002-10-04 21:28:13.409+02 | 402002-10-04 17:35:50.954+02 | 402002-10-04 23:31:27.566+02 | 402002-10-04 23:34:18.286+02 | 402002-10-07 13:48:14.275+02 | 402002-10-07 13:50:04.352+02 | 402002-10-07 14:10:01.441+02 | 402002-10-11 12:57:53.458+02 | 412002-10-11 13:24:49.124+02 | 412002-10-13 16:26:52.546+02 | 412002-10-14 23:50:51.131+02 | 412002-10-15 14:54:12.341+02 | 422002-10-15 15:09:36.84+02  | 422002-10-15 15:21:26.59+02  | 422002-10-20 12:14:05.203+02 | 422002-10-20 20:19:44.309+02 | 422002-10-21 14:23:31.425+02 | 422002-10-22 12:12:31.63+02  | 432002-10-23 14:00:18.478+02 | 43
(25 rows)

Now - my question is, why is monday 21. in week 42, but tuesday 22. in week 
43?

-- 
Andreas Joseph Krogh 
- There are 10 kinds of people in the world, those that can do binary arithmetic and those that can't.


Re: Problems with to_char(created, 'WW')

От:
Karel Zak <zakkr@zf.jcu.cz>
Дата:
On Thu, Oct 24, 2002 at 12:51:35PM +0200, Andreas Joseph Krogh wrote:
> 
> janerik=# select created, to_char(created, 'WW') as week from session WHERE
> username IS NULL ORDER BY week;
Please, see docs and 'IW' (ISO week).
   Karel

-- Karel Zak  http://home.zf.jcu.cz/~zakkr/C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

Re: Problems with to_char(created, 'WW')

От:
Tomasz Myrta <jasiek@klaster.net>
Дата:
Uz.ytkownik Andreas Joseph Krogh napisa?:
> 
> Now - my question is, why is monday 21. in week 42, but tuesday 22. in week 
> 43?

Read the documentation - 4.7. Data Type Formatting Functions
"WW - week number of year (1-53) where first week start on the first day 
of the year"

Year 2002 started on Tuesday, so monday is still week 42, but tuesday is 
week 43.

Tomasz Myrta


FAQ