Mysql Time_to_sec Function

MySQL: TIME_TO_SEC Function

This tutorial explains how to use the MySQL TIME_TO_SEC function with syntax and examples.

Description

The MySQL TIME_TO_SEC function converts a time value into numeric seconds.

Syntax

The syntax for the TIME_TO_SEC function in MySQL is:

TIME_TO_SEC( time )

Parameters or Arguments

time

The time value to convert to numeric seconds.

Note

Applies To

The TIME_TO_SEC function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL TIME_TO_SEC function examples and explore how to use the TIME_TO_SEC function in MySQL.

For example:

mysql> SELECT TIME_TO_SEC('00:00:01');
Output: 1

mysql> SELECT TIME_TO_SEC('00:00:01.999999');
Output: 1

mysql> SELECT TIME_TO_SEC('00:00:02');
Output: 2

mysql> SELECT TIME_TO_SEC('02:13:21');
Output: 8001

mysql> SELECT TIME_TO_SEC('09:36:02');
Output: 34562

mysql> SELECT TIME_TO_SEC('-01:56:45');
Output: -7005