Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert number INT in minutes to TIME in MySQL

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

like image 676
rodrixd Avatar asked Dec 20 '13 14:12

rodrixd


People also ask

How do you convert seconds to HH MM SS in MySQL?

The SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds.

Is int and Integer same in MySQL?

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 .


2 Answers

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
like image 139
Nonguru Avatar answered Oct 06 '22 00:10

Nonguru


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.

like image 35
shadowjfaith Avatar answered Oct 06 '22 01:10

shadowjfaith