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
Parameter | Type | Required | Description |
---|---|---|---|
timestamp | TIMESTAMP | Yes | The TIMESTAMP to truncate |
unit | VARCHAR | Yes | The 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