SEC_TO_TIME() Function Examples – MySQL

Here, we will demonstrate how to works the sec_to_time() function of MySQL and how to use this function with various 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.

If you have any questions or thoughts to share, use the comment form below to reach us.

Spread the love