Convert HH:MM:SS string to number of minutes

后端 未结 8 635
醉梦人生
醉梦人生 2021-01-22 12:03

I have the below query.

select cast(dateadd(minute, datediff(minute, TimeIn, TimeOut), 0) as time(0) )

I get the results from two columns in th

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-22 12:45

    SQL Server Query:

    SELECT cast(substring('02:47:00',1,2) AS int)*60+
           cast(substring('02:47:00',4,2) AS int)+ 
           cast(substring('02:47:00',7,2) AS int)/60.0 AS minutes
    

    MYSQL Query:

    SELECT TIME_TO_SEC('02:47:00') / 60
    

    Result:

    | MINUTES |
    -----------
    |     167 |
    

提交回复
热议问题