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.3. v2.5 supports converting a given time into the end of a time interval.

Syntax

Parameters

  • dt: the time to convert, DATETIME.
  • INTERVAL N type: the time granularity, for example, interval 5 second.
    • 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, MILLISECOND (since 3.1.7), and MICROSECOND (since 3.1.7).
  • 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. This parameter is supported from v2.5.

Return value

Returns a value of the DATETIME type.

Usage notes

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

Examples

The following examples are provided based on the test_all_type_select table.
Example 1: Convert a given DATETIME value to the beginning of a 5-second time interval without specifying the boundary parameter.
Example 2: Convert a given DATETIME value to the beginning of a 5-day time interval with boundary set to FLOOR.
Example 3: Convert a given DATETIME value to the end of a 5-day time interval.
Example 4: Convert a given DATETIME value to the end of a 1-millisecond time interval.
Example 5: Convert a given DATETIME value to the end of a 1-microsecond time interval.