The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
Typed dateDATE '2026-08-12'View examples
Local timestampTIMESTAMP '2026-08-12 09:30:00'View examples
Instant with offsetTIMESTAMPTZ '2026-08-12 09:30:00-03:00'View examples
Transaction timeCURRENT_TIMESTAMPView examples
Wall-clock timeclock_timestamp()View examples
Typed durationINTERVAL '2 days 3 hours'View examples
Add a durationstarted_at + INTERVAL '30 minutes'View examples
Render in a zoneoccurred_at AT TIME ZONE 'America/Sao_Paulo'View examples
Truncate to a unitdate_trunc('month', occurred_at, 'UTC')View examples
Extract a fieldEXTRACT(ISODOW FROM occurred_at)View examples
Half-open time windowWHERE occurred_at >= $1 AND occurred_at < $2View examples
Format for displayto_char(occurred_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI')View examples

Use date for calendar dates, timestamp with time zone for real instants, timestamp without time zone for local wall-clock values whose zone is supplied separately, and interval for durations. Prefer typed ISO literals and define business time-zone and boundary rules explicitly.

Step by step

Detailed examples

01

Choose a type from the meaning

date stores a calendar day. timestamptz stores an instant and displays it in the session TimeZone; it does not preserve the input zone name. timestamp stores fields without a zone. Avoid time with time zone for most application models because a time-zone offset without a date cannot capture seasonal rules.

Declare typed temporal values
SELECT DATE '2026-08-12' AS day,
       TIMESTAMP '2026-08-12 09:30:00' AS local_time,
       TIMESTAMPTZ '2026-08-12 09:30:00-03:00' AS instant;
Back to quick reference ↑
02

Know which clock a function represents

CURRENT_TIMESTAMP and now() return the transaction start; statement_timestamp() returns statement start; clock_timestamp() changes during execution. Transaction-stable time supports consistent auditing, while elapsed-time measurement needs an actual clock.

Compare stable and real clocks
SELECT CURRENT_DATE, CURRENT_TIMESTAMP, statement_timestamp(), clock_timestamp();
Back to quick reference ↑
03

Distinguish calendar arithmetic from fixed seconds

Intervals can contain months, days, and microseconds. A day added across daylight-saving transitions may not equal 24 elapsed hours in a local zone. Define whether a requirement means calendar recurrence or an exact duration and test month-end behavior.

Create an expiry instant
WITH jobs(started_at) AS (VALUES (TIMESTAMPTZ '2026-08-12 12:00:00+00'))
SELECT started_at, started_at + INTERVAL '30 minutes' AS expires_at FROM jobs;
Back to quick reference ↑
04

Convert at explicit system boundaries

AT TIME ZONE converts timestamptz to local timestamp, or interprets a timestamp as local in a named zone and returns an instant. Use IANA zone names for civil-time rules rather than fixed abbreviations. Store instants and retain a separate zone identifier when future local scheduling must preserve regional rules.

Render one instant in two zones
WITH event(instant) AS (VALUES (TIMESTAMPTZ '2026-08-12 12:00:00+00'))
SELECT instant AT TIME ZONE 'America/Sao_Paulo' AS sao_paulo,
       instant AT TIME ZONE 'Asia/Tokyo' AS tokyo
FROM event;
Back to quick reference ↑
05

Bucket in the business zone

date_trunc sets less-significant fields to zero and can accept a zone for timestamptz. EXTRACT returns numeric fields; ISO day and ISO year rules differ around calendar-year edges. Ensure indexes and queries use compatible expressions when bucketing large tables.

Count events by UTC day
SELECT date_trunc('day', occurred_at, 'UTC') AS utc_day, COUNT(*)
FROM events
GROUP BY utc_day
ORDER BY utc_day;
Back to quick reference ↑
06

Use half-open ranges and format last

Half-open [start,end) predicates chain adjacent windows without double counting and avoid guessing timestamp precision. Keep temporal types through filtering and sorting; to_char returns text for a presentation boundary and should not replace typed comparisons.

One UTC calendar day
SELECT event_id, occurred_at
FROM events
WHERE occurred_at >= TIMESTAMPTZ '2026-08-12 00:00:00+00'
  AND occurred_at <  TIMESTAMPTZ '2026-08-13 00:00:00+00'
ORDER BY occurred_at;
Back to quick reference ↑

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. PostgreSQL Global Development GroupPostgreSQL: Date/Time Typespostgresql.org
  2. PostgreSQL Global Development GroupPostgreSQL: Date/Time Functions and Operatorspostgresql.org
  3. PostgreSQL Global Development GroupPostgreSQL: Data Type Formatting Functionspostgresql.org

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback