TIME_TO_SEC( )

This MySQL function returns the number of seconds that the given time represents.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

TIME_TO_SEC(time)

Explanation

This function returns the number of seconds that the given time represents. It's the inverse of SEC_TO_TIME( ).

Examples

SELECT TIME_TO_SEC('01:00')
AS 'Seconds to 1 a.m.';

+-------------------+
| Seconds to 1 a.m. |
+-------------------+
|              3600 | 
+-------------------+

Here we're calculating the number of seconds up until 1 AM (i.e., 60 seconds times 60 minutes) or one hour into the day.