MySQL SEC_TO_TIME() function
In this context, we will learn how we can use the MySQL SEC_TO_TIME() function with proper syntax and good examples.
Introduction of MySQL SEC_TO_TIME() function
This function in MySQL is used to return a time value based on the specific value. Here, the returned time value will be in the format of HH:MM:SS. For example, if the specified second value is 63, this function will return "00:01:03".
Syntax of the MySQL SEC_TO_TIME() function
The syntax of the MySQL SEC_TO_TIME() function is given as follows:
SEC_TO_TIME(scnds)
Parameters or arguments used in MySQL SEC_TO_TIME() function:
There is only one parameter accepted by the SEC_TO_TIME() function in MySQL, which is given as follows:
SCNDS: It is the mentioned seconds value. This value may be both positive or negative in MySQL.
Returns:
It will return a time value based on the mentioned seconds value.
Application used for SEC_TO_TIME() function:
The SEC_TO_TIME() function can be used in the given below MySQL versions.:
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
- MySQL 4.0
- MySQL 3.23
Examples of MySQL SEC_TO_TIME() function:
Now we will look into some MySQL SEC_TO_TIME() function examples and will explore how we can use the SEC_TO_TIME function in MySQL.
Example 1:
In this example, we will get the time value of "00:00:30" from the specified parameter of 30 seconds value in MySQL.
SELECT SEC_TO_TIME(30);
Output:
00:00:30
1 row in set (0.00 sec)
Example 2:
In this example, we will get the time value of "00:01:30" from the specified parameter of 90 seconds value in MySQL.
SELECT SEC_TO_TIME(90);
Output:
00:01:30
1 row in set (0.00 sec)
Example 3:
In this example, we will get the time value of "01:00:35" from the specified parameter of 3635 seconds value.
SELECT SEC_TO_TIME(3635);
Output:
01:00:35
1 row in set (0.00 sec)
Application of MySQL SEC_TO_TIME() function:
This function is used to return a time value based on the specified seconds value.
Summary:
In the above context, we have learned how we can use the SEC_TO_TIME() function used to return a time value based on the specified seconds value.