PostgreSQL 18 reference · Date and Time Functions

PostgreSQL DATE_BIN() Function

Round a timestamp down into fixed-size buckets, such as 15-minute slots, counted from an origin.

PostgreSQL 18 Since 14

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

date_bin(stride, source, origin)

Parameters

ParameterDescription
stride The bucket size, as an interval.
source The timestamp.
origin Where buckets start.

Return value

A timestamp or timestamptz.

Examples

15-minute slots
SELECT date_bin('15 minutes', TIMESTAMP '2026-03-09 10:37', TIMESTAMP '2026-01-01') AS slot;

Output

        slot
---------------------
 2026-03-09 10:30:00
(1 row)

Run this on your computer — see “Get Started” for setup.

Weeks starting on a Monday
SELECT date_bin('7 days', order_date::timestamp, TIMESTAMP '2026-01-05')::date AS week, count(*) AS orders
FROM orders
GROUP BY week
ORDER BY week
LIMIT 3;

Output

    week    | orders
------------+--------
 2026-01-05 |      1
 2026-01-12 |      1
 2026-02-02 |      1
(3 rows)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 14Added

Was this page helpful?