Diberikan expr tanggal atau waktu, mengembalikan jumlah detik sejak tahun 0. Jika expr bukan nilai tanggal atau waktu yang valid (termasuk NULL), ia mengembalikan NULL.
SELECT TO_SECONDS(950501);
62966505600
SELECT TO_SECONDS('2009-11-29');
63426672000
SELECT TO_SECONDS('2009-11-29 13:43:32');
63426721412
SELECT TO_SECONDS( NOW() );
63426721458
Like TO_DAYS(), TO_SECONDS() is not intended for use with values that precede the advent of the Gregorian calendar (1582), because it does not take into account the days that were lost when the calendar was changed. For dates before 1582 (and possibly a later year in other locales), results from this function are not reliable. See Section 13.2.7, “What Calendar Is Used By MySQL?”, for details.
SELECT TO_SECONDS(950501);
62966505600
SELECT TO_SECONDS('2009-11-29');
63426672000
SELECT TO_SECONDS('2009-11-29 13:43:32');
63426721412
SELECT TO_SECONDS( NOW() );
63426721458
Like TO_DAYS(), TO_SECONDS(), converts two-digit year values in dates to four-digit form using the rules in Section 13.2, “Date and Time Data Types”.
SELECT TO_SECONDS('0000-00-00');
+--------------------------+
| TO_SECONDS('0000-00-00') |
+--------------------------+
| NULL |
+--------------------------+
1 row in set, 1 warning (0.00 sec)
SHOW WARNINGS;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1292 | Incorrect datetime value: '0000-00-00' |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)
SELECT TO_SECONDS('0000-01-01');
+--------------------------+
| TO_SECONDS('0000-01-01') |
+--------------------------+
| 86400 |
+--------------------------+
1 row in set (0.00 sec)