Truncate a date or timestamp to a specified unit of precision (year, month, day, hour, etc.), zeroing out all smaller units.
Truncates a date or timestamp to a specified unit, rounding down to the start of that unit. Useful for bucketing events into time windows: date_trunc(hour, created_at). Much faster than EXTRACT for grouping by time periods.
Compatibility
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | Not Supported | - | No DATE_TRUNC(). Use DATE_FORMAT() or arithmetic with DATE() and LAST_DAY(). For truncation to a specific unit, combine YEAR/MONTH/DAY extraction and MAKEDATE/MAKETIME. |
| PostgreSQL | Native | all | DATE_TRUNC(unit, timestamp [, timezone]). Units: microseconds, milliseconds, second, minute, hour, day, week, month, quarter, year, decade, century, millennium. Optional timezone argument added in PG 12. |
| SQL Server | Native | 2022 | DATE_TRUNC(datepart, date) added in SQL Server 2022. For older versions, use DATEADD/DATEDIFF arithmetic: DATEADD(month, DATEDIFF(month, 0, col), 0). |
| Oracle | Native | all | TRUNC(date, format). Format strings differ from PostgreSQL: 'MM' for month, 'DD' for day, 'HH' for hour, 'YYYY' for year. No direct equivalent for week truncation. |
| SQLite | Not Supported | - | No DATE_TRUNC(). Use strftime() to format and truncate dates. |
Details
PostgreSQL's DATE_TRUNC is the gold standard and supports the widest range of units including quarter and decade. Oracle uses TRUNC() with different format strings. MySQL and SQLite have no native truncation — string formatting via DATE_FORMAT/strftime is the workaround. SQL Server only got DATE_TRUNC in 2022; the DATEADD/DATEDIFF pattern is how everyone was doing it before.
Standard Syntax
Version Support
Per-Database Syntax & Notes
MySQL Alternative syntax
No DATE_TRUNC(). Use DATE_FORMAT() or arithmetic with DATE() and LAST_DAY(). For truncation to a specific unit, combine YEAR/MONTH/DAY extraction and MAKEDATE/MAKETIME.
PostgreSQL Native syntax
DATE_TRUNC(unit, timestamp [, timezone]). Units: microseconds, milliseconds, second, minute, hour, day, week, month, quarter, year, decade, century, millennium. Optional timezone argument added in PG 12.
SQL Server Native syntax
DATE_TRUNC(datepart, date) added in SQL Server 2022. For older versions, use DATEADD/DATEDIFF arithmetic: DATEADD(month, DATEDIFF(month, 0, col), 0).
Oracle Native syntax
TRUNC(date, format). Format strings differ from PostgreSQL: 'MM' for month, 'DD' for day, 'HH' for hour, 'YYYY' for year. No direct equivalent for week truncation.
SQLite Alternative syntax
No DATE_TRUNC(). Use strftime() to format and truncate dates.