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):

  1. yyyy - is replaced by the year in 4 digits (e.g. 2024)

  2. yy - is replaced by the year in 2 digits (the last two digits of the year, e.g. 24)

  3. mm - is replaced by the month in 2 digits (e.g. 01, 02, 12)

  4. m - is replaced by the month in 1-2 digits (e.g.1, 2, 12)

  5. dd - is replaced by the day in 2 digits (e.g. 01, 02, 27)

  6. d - is replaced by the day in 1-2 digits (e.g.1, 2, 27)

  7. HH - is replaced by the hour in 2 digits (e.g. 01, 02, 15)

  8. H - is replaced by the hour in 1-2 digits (e.g.1, 2, 15)

  9. MM - is replaced by the minute in 2 digits (e.g. 01, 02, 45)

  10. M - is replaced by the minute in 1-2 digits (e.g. 01, 02, 45)

  11. SS - is replaced by the seconds in 2 digits (e.g. 01, 02, 23)

  12. 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:

Last updated