tryParseTime

tryParseTime, function

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

Parses a time from source using format and returns a success flag and the time as a fraction of a day. When parsing fails, the number defaults to 0.

Example

table T = with
  [| as Raw |]
  [| "2021-12-02 10:15:00" |]
  [| "2022-06-06 06:30:00" |]
  [| "bad" |]

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

show table "Parsed times" with
  T.Raw
  T.Ok
  T.Parsed

This outputs the following table:

Raw Ok Parsed
2021-12-02 10:15:00 true 0.4270833
2022-06-06 06:30:00 true 0.2708333
bad false 0

Remarks

The format tokens are documented in date and time format.

See also

User Contributed Notes
0 notes + add a note