Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

Date Format Strings

A date format string can contain any of the following format keywords along with other characters. The format keywords in the format string are replaced by corresponding values to get the result. The other characters are displayed as literals.

CC

The century as a two digit number.

YYYY

The year as a four digit number.

YYY

The last three digits of the year.

YY

The last two digits of the year.

Y

The last digit of the year.

Y,YYY

The year as a four digit number with a comma after the first digit.

Q

The quarter of the year as one digit number (with values one, two, three, or four).

MM

The month value as two digit number (in the range 01-12).

MONTH

The name of the month as a string of nine characters (‘JANUARY’ to ‘DECEMBER’).

MON

The first three characters of the name of the month (in the range ‘JAN’ to ‘DEC’).

WW

The week of year as a two digit number (in the range 01-52).

W

The week of month as a one digit number (in the range 1-5).

DDD

The day of year as a three digit number (in the range 001-365).

DD

The day of month as a two digit number (in the range 01-31).

D

The day of week as a one digit number (in the range 1-7, 1 for Sunday and 7 for Saturday).

DAY

The day of week as a nine character string (in the range ‘SUNDAY’ to ‘SATURDAY’.

DY

The day of week as a three character string (in the range ‘SUN’ to ‘SAT’).

J

The Julian day (number of days since DEC 31, 1899) as an eight digit number.

TH

When added to a format keyword that results in a number, this format keyword (‘TH’) is replaced by the string ‘ST’, ‘ND’, ‘RD’ or ‘TH’ depending on the last digit of the number.

Example

SELECT C1 FROM T2;

C1

--

09/29/1952

1 record selected

SELECT TO_CHAR(C1, 'Day, Month ddth'),

TO_CHAR(C2, 'HH12 a.m.') FROM T2;

TO_CHAR(C1,DAY, MONTH DDTH) TO_CHAR(C2,HH12 A.M.)

--------------------------- ---------------------

Monday , September 29th 02 p.m.

1 record selected

TOCIndex