From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Shared Method

DateTime.FromString(dateValue As String, locale As Locale = Nil, timeZone as TimeZone = Nil) As DateTime

New in 2019r2

Supported for all project types and targets.

Converts a textual date/time to an actual DateTime using the optional locale and time zone.


If you do not pass in a time zone, the resulting date is in the current time zone.

When no locale is specified, the dateValue parameter can be in either SQLDate (YYYY-MM-DD) or SQLDateTime (YYYY-MM-DD HH:MM:SS) formats.

If you specify a locale, the dateValue text must be formatted to match the locale you specify. For example, specifying the locale as "en-US" would then require the format to be MM/DD/YYYY.

Use format patterns from: Unicode Date Format Patterns.

If you supply a dateValue that that is not in the proper format, a RuntimeException is raised with a Parse Error.

Sample Code

Convert text values to a date:

Var SQLDateTime As String = "2019-08-01 11:00"
Var myDate1 As DateTime = DateTime.FromString(SQLDateTime)

Var SQLDate As String = "2019-08-01"
Var myDate2 As DateTime = DateTime.FromString(SQLDate)

Var dateValue As String = DateTime.Now.ToString(Locale.Current)
Var myDate3 As DateTime = DateTime.FromString(dateValue, Locale.Current, TimeZone.Current)