... I can't see that you can use functions like LEFT, MID and RIGHT on a time because they are stored as decimal numbers...
Function Time12Hour(TimeVal As Double) As String
Dim h As Long
Dim m As Long
Dim s As Long
Dim t As Double
'Remove any date portion
t = TimeVal - Int(TimeVal)
h = Int(t * 24)
m = Int(t * 1440) MOD 60 '1440 = minutes per day
s = Int(86400 * t) MOD 60 '86400 = seconds per day
'convert to 12 hours
h = h MOD 12
if h = 0 then
h = 12
endif
Time12Hour = Str(h) & ":" & Right("00" & Trim(Str(m)),2) & ":" & Right("00" & Trim(Str(s)),2)
End FunctionFunction Time12Hour00(TimeVal As Double) As String
Dim h As Long
Dim m As Long
Dim s As Long
Dim s00 As Long
Dim t As Double
'Remove any date portion
t = TimeVal - Int(TimeVal)
h = Int(t * 24)
m = Int(t * 1440) - 60 * h
s = Int(t * 86400) - 3600 * h - 60 * m
s00 = CLng(t * 8640000) - 360000 * h - 6000 * m - 100 * s
'convert to 12 hours
h = h MOD 12
if h = 0 then
h = 12
endif
Time12Hour00 = Trim(Str(h)) & ":" & Right("00" & Trim(Str(m)),2) & ":" & Right("00" & Trim(Str(s)),2) & "." & Right("00" & Trim(Str(s00)),2)
End Function
Function Time12Hour(TimeVal As Double) As String
Dim h As Long
Dim m As Long
Dim s As Long
Dim t As Double
'Remove any date portion
t = TimeVal - Int(TimeVal)
h = Int(t * 24)
m = Int(t * 1440) - 60 * h
s = CLng(t * 86400) - 3600 * h - 60 * m
if s = 60 then
s = 0
m = m + 1
if m = 60 then
m = 0
h = (h + 1) MOD 24
endif
endif
'convert to 12 hours
h = h MOD 12
if h = 0 then
h = 12
endif
Time12Hour = Trim(Str(h)) & ":" & Right("0" & Trim(Str(m)),2) & ":" & Right("0" & Trim(Str(s)),2)
End Function
Users browsing this forum: No registered users and 23 guests