TimeValue Function |
Named Arguments
No
Syntax
TimeValue(time)
time
Use: Required
Data Type: String
Any valid string representation of a time.
Return Value
A Variant of sub data type Date.
Description
Converts a string representation of a time to a Variant Date data type.
Rules at a Glance
If time is invalid, a runtime error is generated.
If time is Null, TimeValue returns Null.
Both 12- and 24-hour clock formats are valid.
Any date information contained within time is ignored by the TimeValue function.
Programming Tips and Gotchas
A time literal can also be assigned to a Variant or Date variable by surrounding the date with hash characters (#), as the following snippet demonstrates:
Dim dMyTime As Date dMyTime = #12:30:00 AM#
The CDate function can also cast a time expression contained within a string as a Date variable, with the additional advantage of being internationally aware.
See Also
- CDate Function, TimeSerial Function
Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.