Re: current_date / datetime stuff

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Netzach <psql-novice(at)netzach(dot)co(dot)il>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: current_date / datetime stuff
Date: 2007-06-04 16:43:26
Message-ID: C619047D-0223-44E6-92DB-8E29F9E16BE9@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message operationsengineer1 2007-06-04 20:57:45 Laptop Mobo Dead...
Previous Message David Gardner 2007-06-04 16:32:33 Re: Retreving count of rows returned by a join query