How to Change Seconds to a Time Value in SQL

To convert seconds into a time value in SQL, use the SEC_TO_TIME() function. This function takes a single argument, which is the number of seconds you want to convert. For example, if you wanted to convert the number of seconds 12345 into a time value, you would use the following query:

SELECT SEC_TO_TIME(12345);

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called times with the following data:

times
seconds
12345
54321

If you wanted to convert the seconds into a time value, you would use the following query:

SELECT SEC_TO_TIME(seconds) FROM times;

This query would return the results 03:25:45 and 15:05:21, respectively.

Additional Info

The SEC_TO_TIME() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database. 🤓

Want to build your own LLM Apps with AirOps👇👇