TimeValue Function |
Microsoft.VisualBasic.DateAndTime
TimeValue( stringtime )
Any valid string representation of a time
A Date containing the time specified by the string argument, with the date set to January 1 of the year 1
Converts a string representation of a time to a Date data type
If stringtime is invalid, a runtime error is generated.
If stringtime is Nothing , TimeValue generates an error.
stringtime can be in any time format recognized by the IsDate function. Both 12- and 24- hour clock formats are valid.
The Date value returned by time is formatted based on the system's regional settings.
A time literal can also be assigned to a 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.
The string returned by the TimeString property also includes an invalid date, 01/01/0001. It can be eliminated with the Format or FormatDateTime function as follows :
Format(TimeOfDay( ), "Long Time") FormatDateTime(TimeOfDay( ), DateFormat.LongTime)
In VB 6, TimeValue returns the time only. In VB.NET, the function also returns an invalid date, 01/01/0001, along with the time.
TimeOfDay Property, TimeSerial Function, TimeString Property