Skip to main content

Overview

The TIMESTAMP_TRUNC() function rounds a timestamp to a specific day_time granularity, resulting in a truncated timestamp.

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:
The final result will display the current date and time in your timezone:

Case #2: TIMESTAMP_TRUNC() - Minute

Here we will truncate the specified timestamp into the nearest value:
The result will return the truncated timestamp as shown below:

Case #3: Basic TIMESTAMP_TRUNC() function - Year

Run the following query to round the date to the closest value:
The function will truncate the year and return the following result: