DATETOTEXT
Converts a datetime value into a text with a user-defined format.
Syntax
DATETOTEXT(datetime, formatstring)
datetime - the datetime value to be converted into a text - Value type: datetime
formatstring - the format string for the conversion of datetime - Value type: text
The conversion by formatstring follows these rules (case-sensitive):
yyyy - is replaced by the year in 4 digits (e.g. 2024)
yy - is replaced by the year in 2 digits (the last two digits of the year, e.g. 24)
mm - is replaced by the month in 2 digits (e.g. 01, 02, 12)
m - is replaced by the month in 1-2 digits (e.g.1, 2, 12)
dd - is replaced by the day in 2 digits (e.g. 01, 02, 27)
d - is replaced by the day in 1-2 digits (e.g.1, 2, 27)
HH - is replaced by the hour in 2 digits (e.g. 01, 02, 15)
H - is replaced by the hour in 1-2 digits (e.g.1, 2, 15)
MM - is replaced by the minute in 2 digits (e.g. 01, 02, 45)
M - is replaced by the minute in 1-2 digits (e.g. 01, 02, 45)
SS - is replaced by the seconds in 2 digits (e.g. 01, 02, 23)
S - is replaced by the seconds in 1-2 digits (e.g. 01, 02, 23)
Remark
datetime is always in UTC time. If the text is to be converted to local time, datetime must be adjusted using the GETTIMEZONEOFFSET function.
Example
DATETOTEXT with one value: