Seconds Since the Beginning of the Day : Introduction « Date Time Functions « MySQL Tutorial






TIME_TO_SEC(time) returns the time in seconds (the number of seconds since the beginning of that day).

SEC_TO_TIME(seconds) does the opposite, converting the number of seconds from the beginning of the day into HH:MM:SS or HHMMSS format.

mysql>
mysql> select TIME_TO_SEC('01.00.00');
+-------------------------+
| TIME_TO_SEC('01.00.00') |
+-------------------------+
|                       1 |
+-------------------------+
1 row in set, 1 warning (0.00 sec)

mysql>
mysql> SELECT TIME_TO_SEC(110);
+------------------+
| TIME_TO_SEC(110) |
+------------------+
|               70 |
+------------------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT SEC_TO_TIME(70);
+-----------------+
| SEC_TO_TIME(70) |
+-----------------+
| 00:01:10        |
+-----------------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT SEC_TO_TIME(1000)+0;
+---------------------+
| SEC_TO_TIME(1000)+0 |
+---------------------+
|         1640.000000 |
+---------------------+
1 row in set (0.02 sec)

mysql>








14.1.Introduction
14.1.1.Date and Time Functions
14.1.2.Extraction Functions
14.1.3.Changing Date Values
14.1.4.Getting Day Information
14.1.5.Getting Names for Months and Days
14.1.6.Extracting Years, Quarters, Months, and Weeks
14.1.7.Current Date and Time
14.1.8.Days Since 1 A.D.
14.1.9.Seconds Since the Beginning of the Day