Mysql Sec_to_time Function

MySQL: SEC_TO_TIME Function

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

Description

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

Syntax

The syntax for the SEC_TO_TIME function in MySQL is:

SEC_TO_TIME( seconds )

Parameters or Arguments

seconds

A numeric value representing the number of seconds. This value can be positive or negative.

Note

  • Time values range from '-838:59:59' to '838:59:59'.
  • The SEC_TO_TIME function will format the result as "HH:MM:SS".
  • See also the TIME_TO_SEC function.

Applies To

The SEC_TO_TIME 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 SEC_TO_TIME function examples and explore how to use the SEC_TO_TIME function in MySQL.

For example:

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

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

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

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

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