dbTalk Databases Forums  

week format?

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss week format? in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
crystal clear
 
Posts: n/a

Default week format? - 06-14-2004 , 10:48 AM






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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.