w3resource

MySQL SEC_TO_TIME() function

SEC_TO_TIME() function

MySQL SEC_TO_TIME() returns a time value by converting the seconds specified in the argument. The return value is in hours, minutes and seconds. The range of the result is in the time data type.

This function is useful in -

  • SEC_TO_TIME() aids in presenting time-based data in a way that is more intuitive and user-friendly.
  • The function is useful when formatting time durations for display in user interfaces or reports.
  • SEC_TO_TIME() allows you to transform numerical time values into a more meaningful time format.
  • SEC_TO_TIME() is valuable for presenting time intervals or durations in a format that is easy for humans to understand (hh:mm:ss).
  • The function is used to simplify time calculations involving seconds, making them easier to work with.
  • The function is used for analyzing and reporting time durations in a format that is familiar to users.
  • SEC_TO_TIME() can be used to display performance metrics or time-related benchmarks.

Syntax:

SEC_TO_TIME(secnd);

Where secnd is seconds.

Syntax Diagram:

MySQL SEC_TO_TIME() Function - Syntax Diagram

MySQL Version: 8.0


Pictorial Presentation:

Pictorial Presentation of MySQL SEC_TO_TIME() function

Example: MySQL SEC_TO_TIME() function

The following statement will return a time value after converting the second's value 3610.

Code:

SELECT SEC_TO_TIME(3610);

Output:

mysql> SELECT SEC_TO_TIME(3610);
+-------------------+
| SEC_TO_TIME(3610) |
+-------------------+
| 01:00:10          | 
+-------------------+
1 row in set (0.02 sec)

Example: SEC_TO_TIME() function in numeric format

The following statement will return the time value after converting the seconds value specified in the argument to hours, minutes and seconds in numeric format.

Code:

SELECT SEC_TO_TIME(3610)+0;

Output:

mysql> SELECT SEC_TO_TIME(3610);
+-------------------+
| SEC_TO_TIME(3610) |
+-------------------+
| 01:00:10          | 
+-------------------+
1 row in set (0.00 sec)

Video Presentation:

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: QUARTER()
Next: SECOND()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mysql/date-and-time-functions/mysql-sec_to_time-function.php