ParseDateTime
Parses a string as a date and time.
Syntax
-
ParseDateTime(s[, parts])
-
s
is a string -
parts
is a string which is any substring of any permutation of "ymdhnsz"
-
Description
ParseDateTime(s)
attempts to parse the string s
as a date and time and returns, if successful, this date and time as a DateTime
structure. The function assumes that the datetime fields are present in s
in the order specified by parts
, which defaults to ymdhnsz
. However, the number of numeric fields in s
need not equal the length of parts
; unassigned fields attain their default value, which is 1
for date fields and 0
for time fields.
The function does not care about the separators used to delimit the numeric fields in s
, but the number of numeric fields in s
must not exceed the length of parts
. Also, the result must be a valid date and time.
If s
contains any of the substrings "pm", "p.m.", or "p. m.", the hour of the result is increased by 12.
Examples
ParseDateTime("2025-04-13 13:10")
date.year: 2025 date.month: April date.day: 13 time.hour: 13 time.minute: 10 time.second: 0 time.millisecond: 0
ParseDateTime("2025-04-13T13:10:28.512")
date.year: 2025 date.month: April date.day: 13 time.hour: 13 time.minute: 10 time.second: 28 time.millisecond: 512
ParseDateTime("2025-04-13")
date.year: 2025 date.month: April date.day: 13 time.hour: 0 time.minute: 0 time.second: 0 time.millisecond: 0
ParseDateTime("2025-04")
date.year: 2025 date.month: April date.day: 1 time.hour: 0 time.minute: 0 time.second: 0 time.millisecond: 0
ParseDateTime("6:20 pm on 5/31 1960", "hnmdy")
date.year: 1960 date.month: May date.day: 31 time.hour: 18 time.minute: 20 time.second: 0 time.millisecond: 0
ParseDateTime("2003-02-29 16:00")
failure
Incompatible datetime string "2003-02-29 16:00". Call stack: ParseDateTime