extract (dow/week from date)

From: Clodoaldo Pinto <clodoaldo(dot)pinto(at)gmail(dot)com>
To: "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: extract (dow/week from date)
Date: 2005-08-21 00:46:19
Message-ID: a595de7a05082017463111b3c6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The extract (dow from date) function returns 0 for Sunday (nice).

My problem is that Sunday is the last day of the week according to
extract (week from date). Is it the expected behavior?

teste=# create table dates (date timestamp);
CREATE TABLE
teste=# insert into dates values ('2005-08-08');
INSERT 0 1
teste=# insert into dates values ('2005-08-09');
INSERT 0 1
teste=# insert into dates values ('2005-08-10');
INSERT 0 1
teste=# insert into dates values ('2005-08-11');
INSERT 0 1
teste=# insert into dates values ('2005-08-12');
INSERT 0 1
teste=# insert into dates values ('2005-08-13');
INSERT 0 1
teste=# insert into dates values ('2005-08-14');
INSERT 0 1
teste=# select date, extract (week from date) as week, extract (dow
from date) as dow
teste-# from dates
teste-# order by date;
date | week | dow
---------------------+------+-----
2005-08-08 00:00:00 | 32 | 1
2005-08-09 00:00:00 | 32 | 2
2005-08-10 00:00:00 | 32 | 3
2005-08-11 00:00:00 | 32 | 4
2005-08-12 00:00:00 | 32 | 5
2005-08-13 00:00:00 | 32 | 6
2005-08-14 00:00:00 | 32 | 0
(7 rows)

In mysql the date functions work as I need it:
order by yearweek(day, 2) desc, dayofweek(day);

Regards,
Clodoaldo Pinto

Attachment Content-Type Size
dow.txt text/plain 428 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2005-08-21 01:03:32 Re: extract (dow/week from date)
Previous Message Geoff Russell 2005-08-21 00:31:50 ipcc climate mdb problem