본문으로 건너뛰기
최종 수정: 에

TO_SECONDS

설명​

초 단위 계산 함수입니다. 날짜를 초 단위 값으로 변환하며, 기준 날짜 (0000-00-00)부터 지정된 날짜까지의 총 초 수를 계산합니다.

이 함수는 MySQL의 to_seconds 함수와 동일하게 동작합니다.

구문​

TO_SECONDS(`<date_or_time_expr>`)

매개변수​

매개변수설명
<date_or_time_expr>입력 날짜/시간 값입니다. date/datetime 타입을 지원합니다. 구체적인 datetime 및 date 형식은 datetime 변환 및 date 변환을 참조하세요.

반환값​

제로 날짜 (0000-00-00)부터 지정된 날짜와 시간까지의 총 초 수를 BIGINT 타입으로 반환합니다.

입력이 NULL이면 NULL을 반환합니다.

예제​

-- 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 |
+------------------+