TO_CHAR
Convert to string. This function converts a value (often date/time) to a string, potentially using a format mask.
TO_CHAR is available from MariaDB 10.6.
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 secondsDDD– Day (1-366)IW– Week 1-53 according to ISO 8601I– 1-digit year according to ISO 8601IY– 2-digit year according to ISO 8601IYY– 3-digit year according to ISO 8601IYYY– 4-digit year according to ISO 8601SYYY– 4-digit year according to ISO 8601 (Oracle can use signed years)
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.
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
Last updated
Was this helpful?

