Below is a full list of the datetime format elements in Oracle Database.
Element | TO_* datetime functions? | Description |
---|---|---|
- / , . ; : "text" | Yes | Punctuation and quoted text is reproduced in the result. |
AD A.D. | Yes | AD indicator with or without periods. |
AM A.M. | Yes | Meridian indicator with or without periods. |
BC B.C. | Yes | BC indicator with or without periods. |
CC SCC | Century. | |
D | Yes | Day of week (1-7). This element depends on the NLS territory of the session. |
DAY | Yes | Name of day. |
DD | Yes | Day of month (1-31). |
DDD | Yes | Day of year (1-366). |
DL | Yes | Long date format. Determined by the current value of the NLS_DATE_FORMAT parameter. The appearance of the date components (day name, month number, etc) depend on the NLS_TERRITORY and NLS_LANGUAGE parameters. You can specify this format only with the TS element, separated by white space. |
DS | Yes | Short date format. The appearance of the date components (day name, month number, etc) depend on the NLS_TERRITORY and NLS_LANGUAGE parameters.You can specify this format only with the TS element, separated by white space. |
DY | Yes | Abbreviated name of day. |
E | Yes | Abbreviated era name (Japanese Imperial, ROC Official, and Thai Buddha calendars). |
EE | Yes | Full era name (Japanese Imperial, ROC Official, and Thai Buddha calendars). |
FF [1..9] | Yes | Fractional seconds. The optional numbers 1 to 9 specify the number of digits in the fractional second portion of the datetime value returned (e.g. FF3 for 3 digits). If you do not specify a digit, then Oracle Database uses the precision specified for the datetime data type or the data type’s default precision. Valid in timestamp and interval formats, but not in DATE formats. |
FM | Yes | Returns a value with no leading or trailing blanks. |
FX | Yes | Requires exact matching between the character data and the format model. |
HH HH12 | Yes | Hour of day (1-12). |
HH24 | Yes | Hour of day (0-23). |
IW | Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard. A calendar week starts on Monday. The first calendar week of the year includes January 4. The first calendar week of the year may include December 29, 30 and 31. The last calendar week of the year may include January 1, 2, and 3. | |
IYYY | 4-digit year of the year containing the calendar week, as defined by the ISO 8601 standard. | |
IYY IY I | Last 3, 2, or 1 digit(s) of the year containing the calendar week, as defined by the ISO 8601 standard. | |
J | Yes | Julian day; the number of days since January 1, 4712 BC. Number specified with J must be integers. |
MI | Yes | Minute (0-59). |
MM | Yes | Month (01-12; January = 01). |
MON | Yes | Abbreviated name of month. |
MONTH | Yes | Name of month. |
PM P.M. | Yes | Meridian indicator with or without periods. |
Q | Quarter of year (1, 2, 3, 4; January – March = 1). | |
RM | Yes | Roman numeral month (I-XII; January = I). |
RR | Yes | Lets you store 20th century dates in the 21st century using only two digits. |
RRRR | Yes | Round year. Accepts either 4-digit or 2-digit input. If 2-digit, provides the same return as RR. If you do not want this functionality, then enter the 4-digit year. |
SS | Yes | Second (0-59). |
SSSSS | Yes | Seconds past midnight (0-86399). |
TS | Yes | Short time format. Makes the appearance of the time components (hour, minutes, etc) depend on the NLS_TERRITORY and NLS_LANGUAGE initialisation parameters.You can specify this format only with the DL or DS element, separated by white space. |
TZD | Yes | Daylight saving information. The TZD value is an abbreviated time zone string with daylight saving information. It must correspond with the region specified in TZR. Valid in timestamp and interval formats, but not in DATE formats. |
TZH | Yes | Time zone hour. Valid in timestamp and interval formats, but not in DATE formats. |
TZM | Yes | Time zone minute. Valid in timestamp and interval formats, but not in DATE formats. |
TZR | Yes | Time zone region information. The value must be one of the time zone region names supported in the database (see how to get valid time zones). Valid in timestamp and interval formats, but not in DATE formats. |
WW | Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year. | |
W | Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh. | |
X | Yes | Local radix character. This is the symbol used to separate the integer part of the value from its fractional part. |
Y,YYY | Yes | Year with comma in this position. |
YEAR SYEAR | Year, spelled out; S prefixes BC dates with a minus sign (- ). | |
YYYY SYYYY | Yes | 4-digit year; S prefixes BC dates with a minus sign (- ). |
YYY YY Y | Yes | Last 3, 2, or 1 digit(s) of year. |
The TO_* datetime functions? column determines whether or not the format element can be used with the TO_*
functions (such as the TO_CHAR(datetime)
function).
How to Use Format Elements
Format elements (sometimes referred to as format specifiers) can be used to construct datetime format models (sometimes referred to as format strings), which determine how the datetime value is displayed.
For example:
SELECT TO_CHAR(DATE '2035-09-26', 'DY, DD MONTH YYYY')
FROM DUAL;
Result:
WED, 26 SEPTEMBER 2035
In this case, I used a format model of DY, DD MONTH YYYY
.
That format model consisted of a bunch of format elements. For example, DY
is a format element, DD
is another, as is MONTH
and YYYY
. Even the comma (,
) is a format element.
Format elements that spell out a word (such as the day name or month name) can be provided in title case (with the first letter in uppercase and the remaining lowercase to produce a matching effect in the result:
SELECT TO_CHAR(DATE '2035-09-26', 'Dy, DD Month YYYY')
FROM DUAL;
Result:
Wed, 26 September 2035
Also, the output for such elements are subject to the session’s language:
ALTER SESSION SET NLS_DATE_LANGUAGE = 'SPANISH';
SELECT TO_CHAR(DATE '2035-09-26', 'Dy, DD Month YYYY')
FROM DUAL;
Result:
Mié, 26 Septiembre 2035
See How to Change the Language for your Oracle Session for more information and examples.
You might also be interested in How to Check the Values of the NLS Parameters.