Returns a Date value containing the time information represented by a string, with the date information set to January 1 of the year 1.
Public Function TimeValue(ByVal StringTime As String) As DateTime
Exception type | Error number | Condition |
---|---|---|
13 | StringTime includes invalid time information. |
You can enter valid times using a 12-hour or 24-hour clock. For example, "2:24 P.M."
and "14:24"
are both valid StringTime arguments.
If the StringTime argument includes date information, TimeValue does not include it in the returned value. However, if StringTime includes invalid time information such as "January 32," an InvalidCastException error occurs.
This example uses the TimeValue function to convert a string to a time. You can also use date literals to directly assign a time to a Date variable.
Dim MyTime As Date MyTime =TimeValue(
"4:35:17 PM")
' Return the time in a Date data type. MyTime = TimeValue(#4:35:17 PM#) ' Return the time in a Date data type.
DateSerial Function | DateValue Function | Hour Function | Minute Function | Now Property | Second Function | TimeSerial Function |