format

format, function

def const pure format(d: date, pattern: text): text
def const pure format(m: month, pattern: text): text
def const pure format(w: week, pattern: text): text

Formats the date d according to the specifiers in pattern.

Examples

d = date(2022, 9, 26)

table T = with
  [| as Pattern |]
  [| "yyyy-MM-dd" |]
  [| "M/dd/yy" |]
  [| "MMM d, yyyy" |]

T.Text = format(d, T.Pattern)

show table "Formats" with
  T.Pattern
  T.Text

This produces the following table:

Pattern Text
yyyy-MM-dd 2022-09-26
M/dd/yy 9/26/22
MMM d, yyyy Sep 26, 2022
m = month(2024, 2)
w = week(2024, 3)

show summary "Formats (month/week)" with
  format(m, "yyyy-MM")
  format(w, "yyyy-MM-dd")

Remarks

The list of supported specifiers is described in datetimeformat. The month and week overloads format the start of the period.

User Contributed Notes
0 notes + add a note