tryParseTime

tryParseTime, pure function

def pure tryParseTime(source: text, format: text) : (boolean, number)
// scalar format version
def pure tryParseTime(source: text; format: text) : (boolean, number)

The first argument is the value to be parsed. The second argument is the time format. The returned Boolean flag is true if the value has been parsed. The returned number value is non-default only if the parsing succeeded.

Example:

table T = with
  [| as Id, as Raw |]
  [| 1, "2021-10-0900:01:00"  |]
  [| 2, "2021-12-02 10:15:00" |]
  [| 3, "2022-06-06 06:30:00" |]
  [| 4, "2022-08-30 05:46:00" |]

T.Ok, T.Parsed = tryParseTime(T.Raw, "yyyy-MM-dd HH:mm:ss")

show table "Results" a1e4 with
  T.Id
  T.Raw
  T.Ok
  T.Parsed

In the likely case where your format is scalar, favor using the scalar format version, by using a ; argument separator after the source:

table T = with
  [| as Id, as Raw |]
  [| 1, "2021-10-0900:01:00"  |]
  [| 2, "2021-12-02 10:15:00" |]
  [| 3, "2022-06-06 06:30:00" |]
  [| 4, "2022-08-30 05:46:00" |]

// note the ';'
T.Ok, T.Parsed = tryParseTime(T.Raw; "yyyy-MM-dd HH:mm:ss")

show table "Results" a1e4 with
  T.Id
  T.Raw
  T.Ok
  T.Parsed

format specification

The tryParseTime function use the format specifiers defined in the Date & time format page.

See also

User Contributed Notes
0 notes + add a note