mysql timediff to hours

前端 未结 10 1760
我寻月下人不归
我寻月下人不归 2020-12-13 08:47

I\'m Trying to get the timediff from my table and convert it to hours (it\'s for an hourly billed service)

SELECT TIME_TO_SEC(TIMEDIFF(endDate,startDa

相关标签:
10条回答
  • 2020-12-13 09:27

    you can use mysql funcion timestampdiff like below

    TIMESTAMPDIFF(HOUR, '2018-06-01 00:00:00', '2018-06-01 12:00:00') 
    
    0 讨论(0)
  • 2020-12-13 09:28

    for getting Diffrence in Hour :

    Hour(TIMEDIFF(date1,date2)) as Hour1
    

    for getting Diffrence in Minute :

    Minute(TIMEDIFF(date1,date2)) as Minute1
    

    for getting Diffrence in Second :

    Second(TIMEDIFF(date1,date2)) as Second1
    
    0 讨论(0)
  • 2020-12-13 09:29
    HOUR(TIMEDIFF(endDate, startDate))
    

    might work—if I'm reading the docs correctly.

    0 讨论(0)
  • 2020-12-13 09:30
    select hour(timediff('2017-01-01 00:00:00', '2017-01-01 00:01:00'));
     return 1
    
    select hour(timediff('2017-01-01 00:01:00', '2017-01-01 00:00:00'));
     return 1 
    
    select time_to_sec(timediff('2017-01-01 00:00:00', '2017-01-01 00:00:05'));
    return -5
    
    select time_to_sec(timediff('2017-01-01 00:00:00', '2017-01-01 00:00:05'))/60 as 'minutes' ;
    return -0.0833  
    

    if you have the seconds you can convert it as you want or what and hours(..) will not use it when i compare because it's always postive value

    0 讨论(0)
提交回复
热议问题