I need help, my problem is to convert an integer representing minutes into a TIME data type in MySQL example:
duration --> time
60 01:00:00
40 00:40:00
30 00:30:00
120 02:00:00
The duration column is my field in my database, I need to do a query that field turning into a time data type, in the command SELECT example:
SELECT any_function(duration)
thanks in advance
The SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds.
The difference between int and integer is that int is a data type, but integer is a group of data types – e.g. int , long , short and byte .
My problem was integer hours to time ie: 8.5 was 8
an a half hours
Use the same method as above but multiply again
SEC_TO_TIME((ScheduledTime*60)*60) give you 08:30:00
This should get you what you want. Multiply your minutes by 60 to get seconds then convert to time.
SELECT SEC_TO_TIME(duration*60)
refer to http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html for time related functions in MySQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With