SECOND_CEIL
Descriptionβ
The function aligns the input datetime value upwards to the nearest second boundary based on the specified period and returns the aligned datetime value.
Syntaxβ
SECOND_CEIL(<datetime>[, <period>][, <origin_datetime>])
Parametersβ
Parameter | Description |
---|---|
<datetime> | Required. The input datetime value. Supports the DATETIME type. |
<period> | Optional. Specifies the number of seconds in each period. Supports positive integers (INT). Defaults to 1 second. |
<origin_datetime> | Optional. The starting point for alignment. Supports the DATETIME type. Defaults to 0001-01-01T00:00:00 if not specified. |
Return Valueβ
- Returns a datetime value representing the input datetime aligned upwards to the nearest specified second boundary.
- If
<datetime>
is NULL, the function returns NULL. - If
<datetime>
is an invalid date (e.g., 0000-00-00T00:00:00), the function returns NULL.
Exampleβ
Only specifying <datetime>
SELECT SECOND_CEIL('2025-01-23 12:34:56');
+-----------------------------------------------------------+
| second_ceil(cast('2025-01-23 12:34:56' as DATETIMEV2(0))) |
+-----------------------------------------------------------+
| 2025-01-23 12:34:56 |
+-----------------------------------------------------------+
Specifying <datetime>
and <origin_datetime>
SELECT SECOND_CEIL('2025-01-23 12:34:56', '2025-01-01 00:00:00');
+---------------------------------------------------------------------------------------------------------+
| second_ceil(cast('2025-01-23 12:34:56' as DATETIMEV2(0)), cast('2025-01-01 00:00:00' as DATETIMEV2(0))) |
+---------------------------------------------------------------------------------------------------------+
| 2025-01-23 12:34:56 |
+---------------------------------------------------------------------------------------------------------+
Specifying <datetime>
and <period>
SELECT SECOND_CEIL('2025-01-23 12:34:56', 5)
+--------------------------------------------------------------+
| second_ceil(cast('2025-01-23 12:34:56' as DATETIMEV2(0)), 5) |
+--------------------------------------------------------------+
| 2025-01-23 12:35:00 |
+--------------------------------------------------------------+
Specifying <datetime>
οΌ<period>
and <origin_datetime>
SELECT SECOND_CEIL('2025-01-23 12:34:56', 10, '2025-01-23 12:00:00');
+-------------------------------------------------------------------------------------------------------------+
| second_ceil(cast('2025-01-23 12:34:56' as DATETIMEV2(0)), 10, cast('2025-01-23 12:00:00' as DATETIMEV2(0))) |
+-------------------------------------------------------------------------------------------------------------+
| 2025-01-23 12:35:00 |
+-------------------------------------------------------------------------------------------------------------+