メインコンテンツまでスキップ
バージョン: 26.x

MINUTE_CEIL

説明

minute_ceil関数は、入力されたdatetime値を指定された分間隔の最も近い上位の値に切り上げます。originが指定されている場合は、それをベースラインとして使用します。指定されていない場合は、デフォルトで0001-01-01 00:00:00を使用します。

日付計算式: $$ \begin{aligned} &\text{minute_ceil}(\langle\text{date_or_time_expr}\rangle, \langle\text{period}\rangle, \langle\text{origin}\rangle) = \ &\min{\langle\text{origin}\rangle + k \times \langle\text{period}\rangle \times \text{minute} \mid \ &k \in \mathbb{Z} \land \langle\text{origin}\rangle + k \times \langle\text{period}\rangle \times \text{minute} \geq \langle\text{date_or_time_expr}\rangle} \end{aligned} $$ $k$は、ベースライン時刻から目標時刻に到達するのに必要な期間数を表します。

構文

MINUTE_CEIL(`<date_or_time_expr>`)
MINUTE_CEIL(`<date_or_time_expr>`, `<origin>`)
MINUTE_CEIL(`<date_or_time_expr>`, `<period>`)
MINUTE_CEIL(`<date_or_time_expr>`, `<period>`, `<origin>`)

パラメータ

Parameterデスクリプション
<date_or_time_expr>切り上げ対象のdatetime値。型はDATETIME。具体的なdatetimeフォーマットについては、datetime conversionを参照してください。
<period>分間隔値。型はINT。各間隔に含まれる分数を表します。
<origin>間隔の開始時点。型はDATETIME。デフォルト値は0001-01-01 00:00:00です。

Return Value

DATETIME型の値を返します。入力されたdatetimeを基に、指定された分間隔の最寄りの値に切り上げた後の時刻値を表します。戻り値の精度は、入力パラメータdatetimeの精度と同じです。

  • <period>が非正数(≤0)の場合、エラーを返します。
  • いずれかのパラメータがNULLの場合、NULLを返します。
  • periodが指定されていない場合、デフォルトで1分間隔となります。
  • <origin>が指定されていない場合、デフォルトで0001-01-01 00:00:00をベースラインとします。
  • 入力がDATE型(年、月、日のみを含む)の場合、時刻部分はデフォルトで00:00:00となります。
  • 計算結果が最大datetime 9999-12-31 23:59:59を超える場合、エラーを返します。
  • <origin>の日時が<period>より後の場合でも、上記の公式に従って計算されますが、期間kは負の値になります。
  • date_or_time_exprにスケールがある場合、返される結果にもスケールがあり、小数部分は0になります。

Examples

-- Using default period of one minute and default origin time 0001-01-01 00:00:00
SELECT MINUTE_CEIL('2023-07-13 22:28:18') AS result;
+---------------------+
| result |
+---------------------+
| 2023-07-13 22:29:00 |
+---------------------+

-- Using five minutes as one period, rounding up with default origin point
SELECT MINUTE_CEIL('2023-07-13 22:28:18.123', 5) AS result;
+----------------------------+
| result |
+----------------------------+
| 2023-07-13 22:30:00.000000 |
+----------------------------+

-- If input datetime is exactly at a period starting point, return the input datetime
SELECT MINUTE_CEIL('2023-07-13 22:30:00', 5) AS result;
+----------------------------+
| result |
+----------------------------+
| 2023-07-13 22:30:00.000000 |
+----------------------------+

-- Only with origin date and specified date
select minute_ceil("2023-07-13 22:28:18", "2023-07-01 12:21:23");
+-----------------------------------------------------------+
| minute_ceil("2023-07-13 22:28:18", "2023-07-01 12:21:23") |
+-----------------------------------------------------------+
| 2023-07-13 22:28:23 |
+-----------------------------------------------------------+

-- Specifying origin time
SELECT MINUTE_CEIL('2023-07-13 22:28:18', 5, '2023-07-13 22:20:00') AS result;
+----------------------------+
| result |
+----------------------------+
| 2023-07-13 22:30:00.000000 |
+----------------------------+

-- Datetime with scale, all decimal places are truncated to 0
SELECT MINUTE_CEIL('2023-07-13 22:28:18.456789', 5) AS result;
+----------------------------+
| result |
+----------------------------+
| 2023-07-13 22:30:00.000000 |
+----------------------------+

--- If the <origin> date and time is after the <period>, it will still be calculated according to the above formula, but the period k will be negative
SELECT MINUTE_CEIL('0001-01-01 12:32:18', 5, '2028-07-03 22:20:00') AS result;
+---------------------+
| result |
+---------------------+
| 0001-01-01 12:35:00 |
+---------------------+

-- Input is of DATE type (default time 00:00:00)
SELECT MINUTE_CEIL('2023-07-13', 30) AS result;
+---------------------+
| result |
+---------------------+
| 2023-07-13 00:00:00 |
+---------------------+

-- Calculation result exceeds maximum datetime 9999-12-31 23:59:59, returns error
SELECT MINUTE_CEIL('9999-12-31 23:59:18', 6);
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.3)[E-218]Operation minute_ceil of 9999-12-31 23:59:18, 6 out of range

-- Period is non-positive, returns error
SELECT MINUTE_CEIL('2023-07-13 22:28:18', -5) AS result;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.3)[E-218]Operation minute_ceil of 2023-07-13 22:28:18, -5 out of range

-- Any parameter is NULL, returns NULL
SELECT MINUTE_CEIL(NULL, 5), MINUTE_CEIL('2023-07-13 22:28:18', NULL) AS result;
+-----------------------+--------+
| minute_ceil(NULL, 5) | result |
+-----------------------+--------+
| NULL | NULL |
+-----------------------+--------+