📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials Date and Time Functions

Date and Time Functions

5 min read
PostgreSQL date functions: NOW() for current time, date_trunc() to round to a period, EXTRACT() for parts, and AGE() for differences. Always use TIMESTAMPTZ to store times in UTC and avoid timezone bugs.

Date/Time Operations

SELECT NOW();                        -- current timestamp
SELECT CURRENT_DATE;                 -- today
SELECT AGE(birthdate) FROM users;   -- human-readable age
SELECT date_trunc('month', NOW()); -- first of month
SELECT NOW() + INTERVAL '7 days';  -- 1 week ahead
SELECT EXTRACT(YEAR FROM NOW());    -- 2024