SQL Server DATE_BUCKET() Function
DATE_BUCKET(datepart, number, date [, origin]) returns the start of the fixed-width bucket containing a date/time value. SQL Server introduced DATE_BUCKET() in SQL Server 2022 (16.x). See Microsoft’s DATE_BUCKET reference.
Syntax
DATE_BUCKET(datepart, number, date [, origin])
datepartandnumberdefine the bucket width, such asminute, 15for 15-minute buckets. Use a supported date part as a literal, not a variable.datemust be a date/time expression such as a typed column or variable. Cast a string literal to a date/time type before passing it toDATE_BUCKET().originis optional and must resolve to the same data type asdate. If omitted, SQL Server uses1900-01-01 00:00:00.000as the origin.numbermust be a positive integer. A negative width is not valid.
DATE_BUCKET() returns the same data type as the date argument. It is available in SQL Server 2022 and later.
Group events into 15-minute buckets
The following query groups typed event timestamps into 15-minute windows:
SELECT DATE_BUCKET(minute, 15, EventTime) AS bucket_start,
COUNT(*) AS event_count
FROM dbo.Events
GROUP BY DATE_BUCKET(minute, 15, EventTime)
ORDER BY bucket_start;
The default origin aligns the buckets to intervals beginning at 00, 15, 30, and 45 minutes past each hour.
Set a custom origin
Use an explicit origin when bucket boundaries must align to a particular timestamp. This example assumes EventTime is datetime2(0), matching the origin variable’s type:
DECLARE @origin datetime2(0) = '2026-01-01T00:05:00';
SELECT DATE_BUCKET(minute, 15, EventTime, @origin) AS bucket_start,
COUNT(*) AS event_count
FROM dbo.Events
GROUP BY DATE_BUCKET(minute, 15, EventTime, @origin)
ORDER BY bucket_start;
For a bucket that starts at a period boundary, see DATETRUNC(). For counting date-part boundaries between two values, see DATEDIFF().