TO_SECONDS()
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 dates 0000-00-00 and 0000-01-01 are considered invalid. MatrixOne year queries should start from 0001. When querying 0000-00-00 and 0000-01-01, TO_SECONDS() returns an error message:
1. mysql> SELECT TO_SECONDS('0000-00-00');
2. ERROR 20301 (HY000): invalid input: invalid datetime value 0000-00-00
3. mysql> SELECT TO_SECONDS('0000-01-01');
4. 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 automatically fills the year 08 to 0008, which is different from MySQL. For more information, see Two-Digit Years in Dates.
Syntax
1. > TO_SECONDS(expr)
expr is a date or datetime value and can be of type DATETIME, DATE, or TIMESTAMP.
Examples
1. mysql> SELECT TO_SECONDS('0001-01-01');
2. +------------------------+
3. | to_seconds(0001-01-01) |
4. +------------------------+
5. | 31622400 |
6. +------------------------+
7. 1 row in set (0.00 sec)
9. mysql> SELECT TO_SECONDS('2023-07-12 08:30:00');
10. +---------------------------------+
11. | to_seconds(2023-07-12 08:30:00) |
12. +---------------------------------+
13. | 63856369800 |
14. +---------------------------------+
15. 1 row in set (0.00 sec)
17. mysql> SELECT TO_SECONDS('2007-10-07');
18. +------------------------+
19. | to_seconds(2007-10-07) |
20. +------------------------+
21. | 63358934400 |
22. +------------------------+
23. 1 row in set (0.00 sec)
25. mysql> SELECT TO_SECONDS('97-10-07');
26. +----------------------+
27. | to_seconds(97-10-07) |
28. +----------------------+
29. | 3085257600 |
30. +----------------------+
31. 1 row in set (0.00 sec)
