Skip to main content

Command Palette

Search for a command to run...

openGauss type conversion function to_char(datetime/interval [, fmt])

Published
1 min read

to_char(datetime/interval [, fmt])

Description: Convert a DATETIME or INTERVAL value of type DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE to TEXT type according to the format specified by fmt.

The optional parameter fmt can be of the following categories: date, time, week, quarter, and century. Each category can have different templates, and the templates can be reasonably combined. Common templates are: HH, MI, SS, YYYY, MM, DD. Templates can have modifiers, a common modifier is FM, which can be used to suppress leading zeros or trailing whitespace. Return value type: text

Example:

openGauss=# SELECT to_char(current_timestamp,'HH12:MI:SS');

to_char

10:19:26 (1 row) Copy after login

openGauss=# SELECT to_char(current_timestamp,'FMHH12:FMMI:FMSS');

to_char

10:19:46 (1 row)