VARCHAR_FORMAT

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram>>-VARCHAR_FORMAT--(--expression--,--format-string--)----------><
 

The VARCHAR_FORMAT function returns a character representation of a timestamp in the format indicated by format-string.

expression
The argument must be an expression that returns a value of one of the following built-in data types: a timestamp, a character string, or a graphic string.

If expression is a character or graphic string, it must not be a CLOB or DBCLOB and its value must be a valid string representation of a timestamp. For the valid formats of string representations of timestamps, see String representations of datetime values.

Leading and trailing blanks are removed from expression, and the resulting substring is interpreted as a timestamp using the format specified by format-string.

format-string
An expression that returns a built-in character string data type or graphic string data type. format-string contains a template of how expression is to be formatted. Leading and trailing blanks are trimmed from format-string. The resulting value is then folded to uppercase, so the characters in the value may be in any case. The only valid format that can be specified for the function is:

'YYYY-MM-DD HH24:MI:SS'

where:

YYYY
4-digit year
MM
Month (01-12, January = 01)
DD
Day of month (01-31)
HH24
Hour of day (00-24, when the value is 24, the minutes and seconds must be 0).
MI
Minutes (00-59)
SS
Seconds (00-59)

The result is the varying-length character string that contains the argument in the format specified by format-string. format-string also determines the length attribute and actual length of the result. If either argument can be null, the result can be null; if either argument is null, the result is the null value.

The CCSID of the result is the default SBCS CCSID of the current server.

Note

Syntax alternatives: TO_CHAR is a synonym for VARCHAR_FORMAT.

Example