TO_SECONDS
デスクリプション
秒数計算関数です。日付を秒数値に変換し、基準日(0000-00-00)から指定された日付までの総秒数を計算します。
この関数はMySQLのto_seconds functionと一貫した動作をします。
Syntax
TO_SECONDS(`<date_or_time_expr>`)
パラメータ
| Parameter | デスクリプション |
|---|---|
<date_or_time_expr> | 入力する日付/時刻の値。date/datetimeタイプをサポートします。特定のdatetimeおよびdateフォーマットについては、datetime conversionおよびdate conversionを参照してください。 |
Return Value
ゼロ日付(0000-00-00)から指定された日付と時刻までの総秒数をBIGINTタイプで返します。
入力がNULLの場合、NULLが返されます。
Examples
-- Based on the date `0000-00-00`
select to_seconds('0000-01-01');
+--------------------------+
| to_seconds('0000-01-01') |
+--------------------------+
| 86400 |
+--------------------------+
-- Starting from 00-00, count 1 day, a total of 24 * 3600 == 86400 seconds.
select to_seconds('2025-01-01'), to_seconds(20250101);
+--------------------------+----------------------+
| to_seconds('2025-01-01') | to_seconds(20250101) |
+--------------------------+----------------------+
| 63902908800 | 63902908800 |
+--------------------------+----------------------+
SELECT
to_seconds('2025-01-01 11:22:33') AS datetime_type,
to_seconds(20250101112233) AS int_type;
+---------------+-------------+
| datetime_type | int_type |
+---------------+-------------+
| 63902949753 | 63902949753 |
+---------------+-------------+
select to_seconds('9999-12-31 23:59:59.999999');
+------------------------------------------+
| to_seconds('9999-12-31 23:59:59.999999') |
+------------------------------------------+
| 315569519999 |
+------------------------------------------+
SELECT to_seconds(NULL);
+------------------+
| to_seconds(NULL) |
+------------------+
| NULL |
+------------------+