Re: EASY QUESTION!!

From: David W Noon <dwnoon(at)spamtrap(dot)ntlworld(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: EASY QUESTION!!
Date: 2003-04-27 10:30:13
Message-ID: m2osn-brf.ln1@my-pc.ntlworld.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sunday 27 Apr 2003 09:03 in
<1cf4c899(dot)0304270003(dot)244d1ce(at)posting(dot)google(dot)com>, dvsangel
(dvsangel(at)dodo(dot)com(dot)au) wrote:

> a column in one of my tables contains dates in the format yyyy-mm-dd
> From these dates I need to find out which dates are sundays.

I assume that the column is a DATE rather than a CHAR(10).

If so, the EXTRACT(DOW FROM ...) function should give you what you want. A
value of 0 means Sunday.

If your column is actually a CHAR(10) then coerce it to being a DATE as you
invoke EXTRACT() as above. YMMV.

For example:

SELECT * FROM some_table
WHERE EXTRACT(DOW FROM date_column) = 0;

or:

SELECT * FROM some_table
WHERE EXTRACT(DOW FROM CAST(char_column AS DATE)) = 0;

See section 4.8.1 in the PostgreSQL User's Guide for more details. [At least
that's where it is in my copy.]

--
Regards,

Dave
======================================================
dwnoon(at)spamtrap(dot)ntlworld(dot)com (David W Noon)
Remove spam trap to reply via e-mail.
======================================================

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Marco Bubke 2003-04-27 10:37:53 Second maximum value
Previous Message dvsangel 2003-04-27 08:03:21 EASY QUESTION!!