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

October 2017




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
Published by jak58. Latest update on August 10, 2010 at 08:24 AM by jak58.
This document, titled "VBA:VB - Convert Hours to decimal and Decimal to hours," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).