DateTime.FromText
Creates a datetimezone from local and universal datetime formats.
Syntax
DateTime.FromText(
text as text,
optional options as any
) as datetime
Remarks
Creates a datetime
value from a textual representation, text
. An optional record
parameter, options
, may be provided to specify additional properties. The record
can contain the following fields:
Format
: Atext
value indicating the format to use. For more details, go to https://go.microsoft.com/fwlink/?linkid=2180104 and https://go.microsoft.com/fwlink/?linkid=2180105. Omitting this field or providingnull
will result in parsing the date using a best effort.Culture
: WhenFormat
is not null,Culture
controls some format specifiers. For example, in"en-US"
"MMM"
is"Jan", "Feb", "Mar", ...
, while in"ru-RU"
"MMM"
is"янв", "фев", "мар", ...
. WhenFormat
isnull
,Culture
controls the default format to use. WhenCulture
isnull
or omitted,Culture.Current
is used.
options
may also be a text value. This has the same behavior as if options
= [Format = null, Culture = options
]
.
Examples
Example #1
Convert <code>"2010-12-31T01:30:00"</code> into a datetime value.
DateTime.FromText("2010-12-31T01:30:25")
Result:
#datetime(2010, 12, 31, 1, 30, 25)
Example #2
Convert <code>"2010-12-31T01:30:00.121212"</code> into a datetime value.
DateTime.FromText("30 Dez 2010 02:04:50.369730", [Format="dd MMM yyyy HH:mm:ss.ffffff", Culture="de-DE"])
Result:
#datetime(2010, 12, 30, 2, 4, 50.36973)
Example #3
Convert <code>"2010-12-31T01:30:00"</code> into a datetime value.
DateTime.FromText("2000-02-08T03:45:12Z", [Format="yyyy-MM-dd'T'HH:mm:ss'Z'", Culture="en-US"])
Result:
#datetime(2000, 2, 8, 3, 45, 12)
Example #4
Convert <code>"20101231T013000"</code> into a datetime value.
DateTime.FromText("20101231T013000", [Format="yyyyMMdd'T'HHmmss", Culture="en-US"])
Result:
#datetime(2010, 12, 31, 1, 30, 0)
Category
DateTime