Convert decimal time to hours and minutes

前端 未结 4 2044
刺人心
刺人心 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:22

    How about you convert to minutes and add to the 00:00 time like so:

    DECLARE @c datetime
    select @c = dateadd(mi,fdsViewTimesheet.perStandardHours*60,'00:00')  
    

    If you wanted to do it in the statement with Time only:

     select CONVERT(TIME,dateadd(mi,fdsViewTimesheet.perStandardHours*60,'00:00')  )
    

    If you have values that are larger than 24 hours, then the standard datetime and time types in sql cannot hold these. They are limited to holding 24 hour ranges. What you would need to do is store the time representation in a string for example like so:

    select cast(floor(fdsViewTimesheet.perStandardHours) as varchar(10)) + ':' + cast(FLOOR( (fdsViewTimesheet.perStandardHours - floor(fdsViewTimesheet.perStandardHours))*60)as varchar(2))
    

提交回复
热议问题