TO_CHAR

Converts the input expression to a character/string using the specified format.

Syntax

TO_CHAR(expression time, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(CAST('01:02:03' AS TIME) , 'HH:MI');
-- 01:02

TO_CHAR(expression date, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(CAST('2021-02-11' AS DATE) , 'yyyy.mm.dd');
-- 2021.02.11

TO_CHAR(expression int32, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(10, '#')
-- 10

TO_CHAR(expression float, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(7.5, '#.#')
-- 7.5

TO_CHAR(expression int64, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(10, '#')
-- 10

TO_CHAR(expression double, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(7.5, '#.#')
-- 7.5

TO_CHAR(expression timestamp, format varchar) → varchar

  • expression: Expression to convert to a string.

  • format: Format to use for the conversion.

Examples

TO_CHAR example
SELECT TO_CHAR(CAST('2013-04-05 01:02:03' AS TIMESTAMP) , 'mm/dd/yyyy, hh:mi');
-- 04/05/2013, 01:02

Last updated