Skip to main content
Converts a given time into the beginning or end of a time interval based on the specified time granularity. This function is supported from v2.5.

Syntax

Parameters

  • dt: the time to convert, DATE.
  • INTERVAL N type: the time granularity, for example, interval 5 day.
    • N is the length of time interval. It must be an INT value.
    • type is the unit, which can be YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND. If type is set to HOUR, MINUTE, or SECOND for a DATE value, an error is returned.
  • boundary: optional. It is used to specify whether to return the beginning (FLOOR) or end (CEIL) of the time interval. Valid values: FLOOR, CEIL. If this parameter is not specified, FLOOR is the default.

Return value

Returns a value of the DATE type.

Usage notes

The time interval starts from A.D. 0001-01-01 00:00:00.

Examples

Example 1: Convert a given time to the beginning of a 5-year time interval without specifying the boundary parameter.
Example 2: Convert a given time to the end of a 5-day time interval.
The following examples are provided based on the test_all_type_select table.
Example 3: Convert a given DATE value to the beginning of a 5-second time interval.
An error is returned because the system cannot find the second part of a DATE value. Example 4: Convert a given DATE value to the beginning of a 5-day time interval.
Example 5: Convert a given DATE value to the end of a 5-day time interval.