parseDate
parseDate, function
def call parseDate(source: text): date
def pure parseDate(source: text, format: text): date
def pure parseDate(source: text; format: text): date
Parses the text source into a date. The call overload attempts to detect
the format from sample values; use the pure overloads with an explicit format
whenever possible. Formats are documented in
Date & time format. Time components are accepted
and discarded; time zone offsets are applied when present.
source: the text to parse.format: the expected date/time format.
Examples
table Items = with
[| as A |]
[| "2012-01-23" |]
[| "2012-02-24" |]
[| "2012-02-25" |]
[| "2012-02-26" |]
[| "2012-02-27" |]
Items.B = parseDate(Items.A; "yyyy-MM-dd")
show table "Parsed dates" with
Items.A
Items.B
This outputs the following table:
| A | B |
|---|---|
| 2012-01-23 | 2012-01-23 |
| 2012-02-24 | 2012-02-24 |
| 2012-02-25 | 2012-02-25 |
| 2012-02-26 | 2012-02-26 |
| 2012-02-27 | 2012-02-27 |
d = parseDate("2021-01-01 23:00:00 -6"; "yyyy-MM-dd HH:mm:ss z")
show scalar "Parsed date" with d
This outputs the following scalar:
| Parsed date |
|---|
| 2021-01-02 |
Errors
If a date cannot be parsed, the function reports an error. Use tryParseDate to handle invalid values.