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