TO_CHAR

Convert to string. This function converts a value (often date/time) to a string, potentially using a format mask.

circle-info

TO_CHAR is available from MariaDB 10.6.arrow-up-right

Syntax

TO_CHAR(expr[, fmt])

Description

The TO_CHAR function converts an expr of type date, datetime, time or timestamp to a string. The optional fmt argument supports YYY/YYY/YY/RRRR/RR/MM/MON/MONTH/MI/DD/DY/HH/HH12/HH24/SS and special characters. The default value is YYYY-MM-DD HH24:MI:SS. TO_CHAR also accepts FM in the format string, which disables padding of all components following it.

FM can be specified multiple times, with each time disabling the previous state:

  • An odd number of FMs disables padding.

  • An even number of FMs enables padding.

These additional formats (for fmt) are available:

  • FF[1-6] – Fractional seconds

  • DDD – Day (1-366)

  • IW – Week 1-53 according to ISO 8601

  • I – 1-digit year according to ISO 8601

  • IY – 2-digit year according to ISO 8601

  • IYY – 3-digit year according to ISO 8601

  • IYYY – 4-digit year according to ISO 8601

  • SYYY – 4-digit year according to ISO 8601 (Oracle can use signed years)

In Oracle, TO_CHAR can also be used to convert numbers to strings, but this is not supported in MariaDB and gives an error.

Examples

See Also

This page is licensed: CC BY-SA / Gnu FDL

spinner

Last updated

Was this helpful?