tryParseDate

tryParseDate, function

map tryParseDate(source: text, format: text): (boolean, date)
def pure tryParseDate(source: text; format: text): (boolean, date)

Parses source according to format and returns a success flag and a date. Time information is accepted but discarded. When parsing fails, the date value defaults to date(2001, 1, 1).

Example

table T = with
  [| as Text |]
  [| "2022-10-18" |]
  [| "10/18/2022" |]
  [| "1990-01-01" |]
  [| "2011-05-07" |]

T.Ok, T.D = tryParseDate(T.Text; "yyyy-MM-dd")

show table "Parsed dates" with
  T.Text
  T.Ok
  T.D

This outputs the following table:

Text Ok D
2022-10-18 true 2022-10-18
10/18/2022 false 2001-01-01
1990-01-01 true 2001-01-01
2011-05-07 true 2011-05-07

Remarks

Use the success flag instead of relying on the default date. The accepted format tokens are documented in date and time format.

See also

User Contributed Notes
0 notes + add a note