Mega Code Archive

 
Categories / MySQL Tutorial / Date Time Functions
 

Seconds Since the Beginning of the Day

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>