воскресенье, 20 июня 2010 г.

PostgreSQL получение дат

PostgreSQL рулит аццко.

SELECT
date_trunc('day', now())::date as today,
(now() - '1day'::interval)::date as yesterday,
date_trunc('week', now())::date as this_week_start,
(date_trunc('week', now())-'1week'::interval)::date as last_week_start,
(date_trunc('week', now())-'1day'::interval)::date as last_week_end,
date_trunc('month', now())::date as this_month_start,
(date_trunc('month', now())-'1month'::interval)::date as last_month_start,
(date_trunc('month', now())-'1day'::interval)::date as last_month_end
;