VBA:VB - Convert Hours to decimal and Decimal to hours

December 2016




Sub ConvertHoursIntoDecimal()
Dim D As Date, TB, Result As Single
    'For example, it can be at a string
    D = "12:15"
    TB = Split(D, ":")
    Result = TB(0) + ((TB(1) * 100) / 60) / 100
End Sub



Sub ConvertDecimalIntoHours()
Dim D As Single, Result, e
    'For example
    D = 1.25
    e = CStr(Round((D - Int(D)) / 100 * 60, 2)) & "0"
    Result = CStr(Int(D)) & ":" & Mid(e, 3, 2)
End Sub

Related :

This document entitled « VBA:VB - Convert Hours to decimal and Decimal to hours » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.