Export (0) Print
Expand All

DateAndTime.TimeValue Method

Returns a Date value containing the time information represented by a string, with the date information set to January 1 of the year 1.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static DateTime TimeValue(
	string StringTime
)

Parameters

StringTime
Type: System.String
Required. String expression representing a date/time value from 00:00:00 on January 1 of the year 1 through 23:59:59 on December 31, 9999.

Return Value

Type: System.DateTime
Returns a Date value containing the time information represented by a string, with the date information set to January 1 of the year 1.

ExceptionCondition
InvalidCastException

StringTime includes invalid date 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 date information, for example "January 32," an InvalidCastException error occurs.

The following 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 thisTime As Date
thisTime = TimeValue("4:35:17 PM")


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft