Dates & time
◈ 2 cardsExtract parts, filter by date, and do date math.
Working with dates
Postgres has first-class date, timestamp, and interval types. Useful tools:
CURRENT_DATE,now()— today / this instantEXTRACT(YEAR FROM d),EXTRACT(MONTH FROM d)— pull out a partdate_trunc('month', d)— round down to the start of a unitage(d),d + INTERVAL '7 days'— date arithmeticto_char(d, 'YYYY-MM')— format as text
SELECT id, ordered_at + INTERVAL '30 days' AS due FROM orders;