


TimeValue
Purpose
Returns the time represented by a String argument.
Arguments
TimeValue( stringexpression )
Notes
The argument stringexpression is a String representing a time from 0:00:00
(12:00:00 A.M.) through 23:59:59 (11:59:59 P.M.). You can enter valid times using
a 12- or 24-hour clock. For example, "2:24PM" and "14:24" are both valid time arguments.
If
stringexpression includes date information, TimeValue does not return it. However, if stringexpression includes valid date information, an error occurs. The TimeValue function returns a Variant of VarType 7 (Date) containing a time that is
stored internally as a double-precision number. This number represents a time
between 0:00:00 and 23:59:59, or 12:00:00 A.M. and 11:59:59 P.M., inclusive.
Example
In this example, the TimeValue function creates a Variant of VarType 7 (Date) for midnight. The Hour, Minute, and Second functions determine the hour, minute, and second values so the difference can
be calculated.
Midnight = TimeValue("23:59:59")
// Get differences.
HourDiff = Hour(Midnight) - Hour(Now)
MinuteDiff = Minute(Midnight) - Minute(Now)
SecondDiff = Second(Midnight) - Second(Now) + 1
If SecondDiff = 60 Then
MinuteDiff = MinuteDiff + 1
// Add 1 to minute.
SecondDiff = 0 ' Zero seconds.
End If
If MinuteDiff = 60 Then
HourDiff = HourDiff + 1
// Add 1 to hour.
MinuteDiff = 0 ' Zero minutes.
End If
TotalMinDiff = (HourDiff * 60) + MinuteDiff
// Get totals.
TotalSecDiff = (TotalMinDiff * 60) + SecondDiff
Msg = "There are a total of " & Format(TotalSecDiff, "#,##0")
Msg = Msg & " seconds until midnight. That translates to "
Msg = Msg & HourDiff & " hours, " & MinuteDiff
Msg = Msg & " minutes, and " & SecondDiff & " seconds."
MsgBox Msg
// Display message.