Convert seconds to a time values in MySQL; In this tutorial, we will learn how to convert second to time value using the MySQL sec_to_time() function with the help of examples.
MySQL SEC_TO_TIME() Function
The Mysql SEC_TO_TIME () function is used to create time values based on a given second.
Note: Basically, you provide a number of seconds as an argument, and it will change it to a time value.
Syntax
The syntax of sec_to_time() function is:
SEC_TO_TIME(seconds);
Hereseconds
is the number of seconds you want to be converted to a time value.
List of Examples –
Let’s take at some MySQL SEC_TO_TIME function examples and find out how to use the SEC_TO_TIME function.
Example-1
Let’s take a simple and basic example of this function is:
SELECT SEC_TO_TIME(100);
Output-1
+------------------+ | SEC_TO_TIME(100) | +------------------+ | 00:01:40 | +------------------+
Example-2
Here, We take an example with the large value:
SELECT SEC_TO_TIME(7555);
Output-2
+-------------------+ | SEC_TO_TIME(7555) | +-------------------+ | 02:05:55 | +-------------------+
Example-3
Take an example of using the SEC_TO_TIME () function in a numerical context.
SELECT SEC_TO_TIME(4555), SEC_TO_TIME(4555) + 0;
Output-3
+-------------------+-----------------------+ | SEC_TO_TIME(4555) | SEC_TO_TIME(4555) + 0 | +-------------------+-----------------------+ | 01:15:55 | 115555| +-------------------+-----------------------+
Conclusion
Here, you have learned how to use SEC_TO_TIME() function with various examples.
Recommended MySQL Tutorials
If you have any questions or thoughts to share, use the comment form below to reach us.