mysql minutes to hours and minutes

前端 未结 5 1234
梦谈多话
梦谈多话 2021-01-12 13:50

I have a table that return minutes from a task and I\'d like to convert into hours and minutes.

my select is:

select
m.mat_nome as \'Matéria\',
round         


        
相关标签:
5条回答
  • 2021-01-12 14:01

    Use the following facts: hours = floor /60 minutes = (-hours*60

    0 讨论(0)
  • 2021-01-12 14:01

    Why not simply do something like this?

    select convert(date_add('2000-01-01', interval 146 minute), time);
    

    This returns 02:26:00

    Or the following if you want to specify return format

    select date_format(date_add('2000-01-01', interval 146 minute), '%h:%i');
    
    0 讨论(0)
  • 2021-01-12 14:03

    This is working! Thanks!

    select
        m.mat_nome as 'Matéria',
        CONCAT(
            FLOOR(
                sum(
                    case when Hour(TIMEDIFF(est_horario_inicial, est_horario_final))*60 = 0 
                        then Minute(TIMEDIFF(est_horario_inicial, est_horario_final))
                        else Hour(TIMEDIFF(est_horario_inicial, est_horario_final))*60
                    end
                )/60
            ),'h', 
            MOD(
                sum(
                    case when Hour(TIMEDIFF(est_horario_inicial, est_horario_final))*60 = 0 
                        then Minute(TIMEDIFF(est_horario_inicial, est_horario_final))
                        else Hour(TIMEDIFF(est_horario_inicial, est_horario_final))*60
                    end
                )
            ,60)
        , 'm')
        as 'tempo' from estudos_realizados e
    left join materias m on e.mat_id = m.mat_id; 
    
    0 讨论(0)
  • 2021-01-12 14:04
    CONCAT(FLOOR(minutes/60),':',LPAD(MOD(minutes,60),2,'0'))
    

    a variation on Damir Kasipovic's code: this converts 62 minutes to '1:02'

    0 讨论(0)
  • 2021-01-12 14:25

    You should look up FLOOR() function, and simple math. You need something like

    CONCAT(FLOOR(minutes/60),'h ',MOD(minutes,60),'m') 
    
    0 讨论(0)
提交回复
热议问题