MySQL: SEC_TO_TIME Function with Examples

MySQL: SEC_TO_TIME Function with Examples

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.

You may like

  1. MySQL CURRENT TIMESTAMP Function Examples
  2. MySQL CURRENT TIME Function Examples
  3. ADDTIME() Function Examples – MySQL
  4. MINUTE() Function Examples – MySQL
  5. HOUR() Function Examples – MySQL
  6. SECOND() Function Examples – MySQL
  7. MICROSECOND() Function Examples – MySQL
  8. TO_DAYS() Function Examples – MySQL
  9. Get month name from date in mysql
  10. mysql get first day of the current month
  11. mysql last day of previous month
  12. Get month number from month name in mysql
  13. mysql get day of week number from date
  14. Mysql Get Data Of Current Date, Week, Month, YEAR
  15. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql

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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.