Re: current_date / datetime stuff

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема Re: current_date / datetime stuff
Дата
Msg-id C619047D-0223-44E6-92DB-8E29F9E16BE9@seespotcode.net
обсуждение исходный текст
Ответ на Re: current_date / datetime stuff  (Netzach <psql-novice@netzach.co.il>)
Список 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 по дате отправления:

Предыдущее
От: David Gardner
Дата:
Сообщение: Re: Retreving count of rows returned by a join query
Следующее
От:
Дата:
Сообщение: Laptop Mobo Dead...