Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DateAndTime.DateValue Method

Returns a Date value containing the date information represented by a string, with the time information set to midnight (00:00:00).

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

public static DateTime DateValue(
	string StringDate


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
Date value containing the date information represented by a string, with the time information set to midnight (00:00:00).


StringDate includes invalid time information.

If StringDate includes only numbers from 1 through 12 separated by valid date separators, DateValue recognizes the order for month, day, and year according to the Short Date format specified for your system. DateValue uses the current calendar setting from the CurrentCulture property of the CultureInfo class in the System.Globalization namespace. The default CurrentCulture values are determined by Control Panel settings. You can override the Short Date format by setting the ShortDatePattern property of the DateTimeFormatInfo class in the System.Globalization namespace.

DateValue recognizes month names in long, abbreviated, and numeric form. For example, in addition to recognizing 12/30/1991 and 12/30/91, DateValue also recognizes December 30, 1991 and Dec 30, 1991.

If the year part of StringDate is omitted, DateValue uses the current year from your computer's system date.

If the StringDate argument includes time information, DateValue does not include it in the returned value. However, if StringDate includes invalid time information, such as "89:98", an InvalidCastException error occurs.

This example uses the DateValue function to convert a string to a date. You can also use date literals to directly assign a date to an Object or Date variable, for example, oldDate = #2/12/69#.

Dim oldDate As Date
oldDate = DateValue("February 12, 1969")

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft