TO_SECONDS()¶
The TO_SECONDS(expr) function is used to calculate the number of seconds between a given date or datetime expr and the year 0, January 1, 00:00:00.
Description¶
The TO_SECONDS(expr) function is used to calculate the number of seconds between a given date or datetime expr and the year 0, January 1, 00:00:00. If expr is NULL, it returns NULL.
Note
The zero date 0000-00-00 returns NULL. The date 0000-01-01 is still considered invalid in MatrixOne and returns an error:
mysql> SELECT TO_SECONDS('0000-00-00');
+------------------------+
| to_seconds(0000-00-00) |
+------------------------+
| NULL |
+------------------------+
1 row in set (0.00 sec)
mysql> SELECT TO_SECONDS('0000-01-01');
ERROR 20301 (HY000): invalid input: invalid datetime value 0000-01-01
Similar to the TO_DAYS() function, for example, when querying SELECT TO_SECONDS('08-10-07');, MatrixOne follows MySQL and completes the year 08 to 2008. For more information, see Two-Digit Years in Dates.
Syntax¶
> TO_SECONDS(expr)
expr is a date or datetime value and can be of type DATETIME, DATE, or TIMESTAMP.
Examples¶
mysql> SELECT TO_SECONDS('0001-01-01');
+------------------------+
| to_seconds(0001-01-01) |
+------------------------+
| 31622400 |
+------------------------+
1 row in set (0.00 sec)
mysql> SELECT TO_SECONDS('2023-07-12 08:30:00');
+---------------------------------+
| to_seconds(2023-07-12 08:30:00) |
+---------------------------------+
| 63856369800 |
+---------------------------------+
1 row in set (0.00 sec)
mysql> SELECT TO_SECONDS('2007-10-07');
+------------------------+
| to_seconds(2007-10-07) |
+------------------------+
| 63358934400 |
+------------------------+
1 row in set (0.00 sec)
mysql> SELECT TO_SECONDS('97-10-07');
+----------------------+
| to_seconds(97-10-07) |
+----------------------+
| 63043401600 |
+----------------------+
1 row in set (0.00 sec)