Algosim documentation: FormatDateTime

FormatDateTime

Formats a date, time, or datetime value in a manually specified format.

Syntax

Description

FormatDateTime(t, fmt) returns a string with the date, time, or datetime value t formatted in the format given by fmt.

fmt is a string that contains placeholders for the various parts of a date and time value:

Symbol Meaning
d Day without leading zero (1–31).
dd Day with leading zero (01–31).
m Month without leading zero (1–12). If immediately preceeded by
h or hh, this symbol is treated as n instead.
mm Month with leading zero (01–12). If immediately preceeded by h
or hh, this symbol is treated as nn instead.
yy Year as a two-digit number (00–99).
yyyy Year as a four-digit number (0000–9999).
h Hour without leading zero (0–23).
hh Hour with leading zero (00–23).
n Minute without leading zero (0–59).
nn Minute with leading zero (00–59).
s Second without leading zero (0–59).
ss Second with leading zero (00–59).
z Millisecond without leading zero (0–999).
zzz Millisecond with leading zero (000–999).
am/pm Makes the preceding h or hh use the 12-hour clock. In addition,
this symbol is replaced by am or pm depending on the time of day.
The character case of the output is exactly the one given by the
symbol. Note that the symbol is a five-character string with a
solidus at the centre; it is not a two-character string.
a/p Makes the preceding h or hh use the 12-hour clock. In addition,
this symbol is replaced by a or p depending on the time of day.
The character case of the output is exactly the one given by the
symbol. Note that the symbol is a three-character string with a
solidus at the centre; it is not a one-character string.
'text' Text enclosed by single or double quotation marks is copied as is
to the output. This is typically used for date and time separators,
such as '-', '/', '.', and ':'.

If omitted, fmt defaults to

yyyy'-'mm"-'dd' 'hh':'nn':'ss

Examples

FormatDateTime(now())
2020-09-05 20:30:50
FormatDateTime(now(), "'┃'hh'┆'nn'┆'ss'┃'")
┃20┆30┆50┃

See also