Convert decimal time to hours and minutes

前端 未结 4 2046
刺人心
刺人心 2020-12-03 15:35

Been struggling with this and can\'t seem to find the right answer, although there are plenty of mentions for converting, but nothing specific is working.

I need to

4条回答
  •  心在旅途
    2020-12-03 16:03

    DECLARE @f FLOAT = 13.5;
    
    SELECT CONVERT(TIME(0), DATEADD(MINUTE, 60*@f, 0));
    

    Or if you just want hh:mm as a string:

    SELECT CONVERT(CHAR(5), DATEADD(MINUTE, 60*@f, 0), 108);
    

    Just be careful if you have values >= 24.

提交回复
热议问题