MySQL SEC_TO_TIME(): Convert Seconds to a Time Values

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.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.