Problems with to_char(created, 'WW')

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: pgsql-sql(at)postgresql(dot)org
Subject: Problems with to_char(created, 'WW')
Date: 2002-10-24 10:51:35
Message-ID: 200210241251.35365.andreak@officenet.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 | 39
2002-09-24 18:19:06.304+02 | 39
2002-09-25 10:50:27.139+02 | 39
2002-09-30 12:32:06.898+02 | 39
2002-10-01 16:26:41.122+02 | 40
2002-10-04 13:47:02.922+02 | 40
2002-10-04 21:28:13.409+02 | 40
2002-10-04 17:35:50.954+02 | 40
2002-10-04 23:31:27.566+02 | 40
2002-10-04 23:34:18.286+02 | 40
2002-10-07 13:48:14.275+02 | 40
2002-10-07 13:50:04.352+02 | 40
2002-10-07 14:10:01.441+02 | 40
2002-10-11 12:57:53.458+02 | 41
2002-10-11 13:24:49.124+02 | 41
2002-10-13 16:26:52.546+02 | 41
2002-10-14 23:50:51.131+02 | 41
2002-10-15 14:54:12.341+02 | 42
2002-10-15 15:09:36.84+02 | 42
2002-10-15 15:21:26.59+02 | 42
2002-10-20 12:14:05.203+02 | 42
2002-10-20 20:19:44.309+02 | 42
2002-10-21 14:23:31.425+02 | 42
2002-10-22 12:12:31.63+02 | 43
2002-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 <andreak(at)officenet(dot)no>
- There are 10 kinds of people in the world, those that can do binary
arithmetic and those that can't.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message andres javier garcia garcia 2002-10-24 10:57:28 ORDER the result of a query by date
Previous Message Tomasz Myrta 2002-10-24 09:39:17 Re: sub-select with aggregate