forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com> Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
9.7 KiB
9.7 KiB
to_char
This function is used to convert a date into a string in a specified format.
Syntax
to_char(string date, string format)
Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
date |
Yes |
DATE or STRING |
Date that needs to be processed The following formats are supported:
|
format |
Yes |
STRING |
Format of the date to be converted Constant of the STRING type. Extended date formats are not supported. The value is a combination of the time unit (year, month, day, hour, minute, and second) and any character.
|
Return Values
The return value is of the STRING type.
Example Code
The static data 2023-08*16 is returned.
select to_char('2023-08-16 10:54:36','Example static data yyyy-mm*dd');
The value 20230816 is returned.
select to_char('2023-08-16 10:54:36', 'yyyymmdd');
The value NULL is returned.
select to_char('Example static data 2023-08-16','Example static data yyyy-mm*dd');
The value NULL is returned.
select to_char('20230816', 'yyyy');
The value NULL is returned.
select to_char('2023-08-16 10:54:36', null);
Parent topic: Date Functions