Xojo.Core.Date.FromText

From Xojo Documentation

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

Xojo.Core.Date.FromText(input As Text, loc As Xojo.Core.Locale = Nil) As Xojo.Core.Date

Supported for all project types and targets.

Converts a textual date to an actual date using the optional locale.

Notes

The resulting date is in the current time zone (Xojo.Core.TimeZone.Current).

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

If you specify a locale, the input text must be formatted to match the locale you specify.

Use format patterns from: Unicode Date Format Patterns.

If you supply input text that cannot be formatted, then a RuntimeException is raised with a Parse Error.

Sample Code

Convert text values to a date:

Var SQLDateTime As Text = "2015-08-01 11:00"
Var myDate1 As Xojo.Core.Date = Xojo.Core.Date.FromText(SQLDateTime)

Var SQLDate As Text = "2018-06-01"
Var myDate2 As Xojo.Core.Date = Xojo.Core.Date.FromText(SQLDate)

Var dateValue As Text = Xojo.Core.Date.Now.ToText(Xojo.Core.Locale.Current)
Var myDate3 As Xojo.Core.Date = Xojo.Core.Date.FromText(dateValue, Xojo.Core.Locale.Current)