EasyDate & Time Functions

DATE_TRUNC: truncate to time period

The query

SQL
SELECT
  order_date,
  DATE_TRUNC('year', order_date) AS year_start,
  DATE_TRUNC('month', order_date) AS month_start,
  DATE_TRUNC('week', order_date) AS week_start,
  DATE_TRUNC('day', order_date) AS day_start,
  DATE_TRUNC('hour', order_date) AS hour_start
FROM orders
LIMIT 10;
Tested against PostgreSQL 16

Note

DATE_TRUNC is essential for time-series grouping. Returns timestamp, not integer like EXTRACT.

Tables referenced