Method

ParseDate


Warning

This item was deprecated in version 2019r2. Please use DateTime.FromString as a replacement.

Description

Parses a date passed as a string and creates a DateTime object.

Usage

result=ParseDate(Text, ByRef ParsedDate)

Part

Type

Description

result

Boolean

Returns True if Text was successfully parsed.

Text

String

The DateTime string to be converted to a DateTime object.

ParsedDate

DateTime

After a successful call, it contains the parsed date as a DateTime object.

Notes

Note

On Windows (due to the Windows API being used), it is not possible to go back further than 1 January 1601.

The Text parameter must be a valid string representation of a DateTime. ParseDate uses the current date formats that are specified in the regional/international system settings on the user's computer. It recognizes those formats. For that reason, the specific formats that ParseDate will support on a particular computer cannot be specified. If you are having problems with a date format, check the International formats (macOS), Regional Settings (Windows), or equivalent feature on Linux to be sure that the format you are using is specified.

For example, if you want to use the dot as the separator in short dates (e.g.,1.6.2005 as January 6, 2005) you need to change the separator to the dot in International/Regional settings. When you do so, the string "1.6.2005" will work. However, "1/6/2005" (or some other separator) will not. Similarly, if you want to use "6Jan2005" then you need to change the "Medium" format in International formats.

You also need to be aware of the order in with the month, day, and year appear in the format specification, as the defaults change by region. For example, the string "12/11/2004" is parsed as the eleventh of December in the US (using the default format and separator, "/"). If the computer is configured for the default British date format, it will be parsed as the twelfth of November.

ParseDate will parse dates based on the user's locale even if the user's locale is a Unicode-only locale.

If the passed date string uses two digits for the year, ParseDate on macOS assumes the current century.

ParseDate does not parse the Time value of a DateTime, if present.

Sample code

The following code attempts to convert a string value to a Date. If it succeeds, the date is displayed:

Dim theDate As New Date
Dim converted As Boolean

' Attempt to convert the string "12/31/2013" to a date. If
' the conversion succeeds, theDate variable contains the converted date.
converted = ParseDate("12/31/2013", theDate)
If converted Then
  MsgBox("Converted to: " + theDate.AbbreviatedDate)
Else
  MsgBox("Could not convert the string to a date.")
End If

Compatibility

All project types on all supported operating systems.

See also

DateTime class, Database class examples.