How to convert seconds to hours in mysql?

by ryan.murray , in category: MySQL , a year ago

How to convert seconds to hours in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , a year ago

@ryan.murray 

You can use the SEC_TO_TIME function in MySQL to convert seconds to hours.


Here is an example query that demonstrates how to do this:

1
SELECT SEC_TO_TIME(3600) AS time_in_hours;


In this example, 3600 is the number of seconds that you want to convert to hours. The SEC_TO_TIME function will convert it to the corresponding time value, which in this case would be 01:00:00.


If you have a column in your table that contains the number of seconds, you can include that column in the SELECT statement to convert the values for each row.


For example, if you have a table called my_table with a column called seconds, you can use the following query:

1
SELECT SEC_TO_TIME(seconds) AS time_in_hours FROM my_table;


This will return the values from the seconds column converted to hours.