week format?

From: crystal clear <crystalclear2323(at)yahoo(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: week format?
Date: 2004-06-14 15:48:28
Message-ID: 20040614154828.27968.qmail@web90109.mail.scd.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

hi! I'm trying to make a select query which displays the entries in my table by week of month, each week beginning on a monday and ending on a sunday, with the 1st monday of the month marking the start of week 1 for the month. I used this:

SELECT * FROM table1 t WHERE EXTRACT (WEEK FROM (t.datetimestamp, 'MM DD YYYY')) =
(SELECT distinct EXTRACT(WEEK FROM (t.datetimestamp, 'MM DD YYYY'))
FROM table1 t WHERE
(EXTRACT (MONTH FROM (t.datetimestamp, 'MM DD YYYY'))= [month])
AND (to_char ((t.datetimestamp, 'MM DD YYYY'), 'W')= [week of month])
AND (EXTRACT(DOW FROM (t.datetimestamp, 'MM DD YYYY')) = [day of week])
AND (EXTRACT (YEAR FROM (t.datetimestamp, 'MM DD YYYY'))= [year]));

replacing items enclosed in [] with appropriate values, although it doesn't work for weeks when there aren't any entries for mondays. Im not sure if i should use this query and find a way to auto-generate data entries for every monday, to make sure that mondays are never null, or if i should just scrap this query and look for another way to change the date format. Any suggestions? :-)


---------------------------------
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger

Browse pgsql-novice by date

  From Date Subject
Next Message jarednevans 2004-06-14 17:50:05 benefits of an Array Column?
Previous Message Tom Lane 2004-06-12 19:38:50 Re: invalid page header