TIMESTAMP_TRUNC
10min
This article will assist you in how to use the TIMESTAMP_TRUNC() function.
Overview
The TIMESTAMP_TRUNC() function rounds a timestamp to a specific day_time granularity, resulting in a truncated timestamp.
Syntax
Syntax
|
day_time can be replaced with various time values as follows:
- SECOND
- MINUTE
- HOUR
- DAY
- MONTH
- YEAR
Examples
#Case 1: TIMESTAMP_TRUNC() - Hour
The following example shows how to round the hour to the closest value:
Timestamp trunc
|
The final result will display the current date and time in your timezone:
Output
|
#Case 2: TIMESTAMP_TRUNC() - Minute
Here we will truncate the specified timestamp into the nearest value:
Timestamp trunc
|
The result will return the truncated timestamp as shown below:
Output
|
#Case 3: Basic TIMESTAMP_TRUNC() function - Year
Run the following query to round the date to the closest value:
Timestamp trunc
|
The function will truncate the year and return the following result:
Output
|

Updated 12 May 2023
Did this page help you?
Yes
No