Re: current_date / datetime stuff - Mailing list pgsql-novice

From Michael Glaesemann
Subject Re: current_date / datetime stuff
Date
Msg-id C619047D-0223-44E6-92DB-8E29F9E16BE9@seespotcode.net
Whole thread Raw
In response to Re: current_date / datetime stuff  (Netzach <psql-novice@netzach.co.il>)
List pgsql-novice
On Jun 4, 2007, at 11:23 , Netzach wrote:

> SELECT ( 1 -
>     extract(dow from ('1/<month>/<year>')::date)::integer
>      + 8
>     ) % 7

> SELECT ( 1 -
>     extract(dow from ('1/<month>/<year>')::date)::integer
>      + 8
>     ) % 7
>     || '/' || '<month>' || '/' || '<year>';

> SELECT ( 1 - firstday::integer + 8 ) % 7  || '/' || month || '/' ||
> year
> FROM (
>     SELECT extract(dow from ('1/'||month||'/'||year)::date) AS firstday,
>         month,year
>     FROM (
>         SELECT extract(month from current_date) AS month,
>         extract(year from current_date) AS year
>     ) AS date_parts
> ) AS date_parts;

> NOTE: Americans may wish to swap the order of day/month. Or not :)
>

PostgreSQL has a large number of useful date manipulation functions
so you can avoid doing this kind of error-prone string work.

http://www.postgresql.org/docs/8.2/interactive/functions-datetime.html

Michael Glaesemann
grzm seespotcode net



pgsql-novice by date:

Previous
From: David Gardner
Date:
Subject: Re: Retreving count of rows returned by a join query
Next
From:
Date:
Subject: Laptop Mobo Dead...