DATE_TRUNC

All functions > DATE_AND_TIME > DATE_TRUNC

Returns the given timestamp truncated to the given unit.

Syntax

DATE_TRUNC(timestamp, unit)
sql

Arguments

ParameterTypeRequiredDescription
timestampTIMESTAMPYesThe TIMESTAMP to truncate
unitVARCHARYesThe time unit to truncate to (e.g., 'day', 'hour', 'month')

Returns

The timestamp truncated to the specified unit

Notes

  • Truncates timestamp to the beginning of the specified unit
  • Common units: 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'
  • Useful for grouping timestamps into time buckets
  • Time components smaller than the unit are set to their minimum values
  • Example: DATE_TRUNC(timestamp, 'day') returns midnight of that day

Examples

Last update at: 2025/10/13 10:23:46