Date and Time Parameters

Previous
Previous
Next
Next

Oracle Database XE enables you to control the display of the date and time, allowing different conventions for displaying the hour, day, month, and year based on the local formats. For example, in the United Kingdom, the date is displayed using the DD/MM/YYYY format, while China commonly uses the YYYY-MM-DD format.

This section contains the following topics:

Date Formats

Different date formats are shown in Table: Examples of Short Date Formats.

Examples of Short Date Formats

Country Description Example

Estonia

dd.mm.yyyy

28.02.2005

Germany

dd.mm.rr

28.02.05

China

yyyy-mm-dd

2005-02-28

UK

dd/mm/yyyy

28/02/2005

US

mm/dd/yyyy

02/28/2005


This section describes the following parameters:

NLS_DATE_FORMAT Parameter

The NLS_DATE_FORMAT parameter defines the default date format to use with the TO_CHAR and TO_DATE functions. The NLS_TERRITORY parameter determines the default value of the NLS_DATE_FORMAT parameter. The value of NLS_DATE_FORMAT can be any valid date format model. For example:

NLS_DATE_FORMAT = "MM/DD/YYYY"

The Oracle default date format may not always correspond to the cultural-specific convention used in a given territory. You can use the short date and long date format in SQL, using the 'DS' and 'DL' format models, respectively, to obtain dates in localized formats. The examples in this section show the differences among some of the date formats.

Example: Using the Default, Short, and Long Date Formats shows the use of the default, short, and long date formats.

Using the Default, Short, and Long Date Formats

-- Use an ALTER SESSION statement to change the territory to America, 
-- and the language to American
ALTER SESSION SET NLS_TERRITORY = America NLS_LANGUAGE = American;

-- After the session is altered, select the dates with the format models
SELECT hire_date, TO_CHAR(hire_date,'DS') "Short", 
  TO_CHAR(hire_date,'DL') "Long" FROM employees
  WHERE employee_id IN (111, 112, 113);

The results of the query in Example: Using the Default, Short, and Long Date Formats should be similar to the following:


HIRE_DATE Short      Long
--------- ---------- -----------------------------
30-SEP-97 9/30/1997  Tuesday, September 30, 1997
07-MAR-98 3/7/1998   Saturday, March 07, 1998
07-DEC-99 12/7/1999  Tuesday, December 07, 1999

To add string literals to the date format, enclose the string literal with double quotes. Note that when double quotation marks are included in the date format, the entire value must be enclosed by single quotation marks. For example:

NLS_DATE_FORMAT = '"Date: "MM/DD/YYYY'

NLS_DATE_LANGUAGE Parameter

The NLS_DATE_LANGUAGE parameter specifies the language for the day and month produced by the TO_CHAR and TO_DATE functions. NLS_DATE_LANGUAGE overrides the language that is specified implicitly by NLS_LANGUAGE. The NLS_DATE_LANGUAGE parameter has the same syntax as the NLS_LANGUAGE parameter, and all supported languages are valid values.

The NLS_DATE_LANGUAGE parameter also determines the language used for:

  • Month and day abbreviations returned by the TO_CHAR and TO_DATE functions

  • Month and day abbreviations used by the default date format (NLS_DATE_FORMAT)

Example: Setting NLS_DATE_LANGUAGE=FRENCH: Month and Day shows how to use NLS_DATE_LANGUAGE to set the date language to French.

Setting NLS_DATE_LANGUAGE=FRENCH: Month and Day

-- set NLS_DATE_LANAGUAGE for this user session
ALTER SESSION SET NLS_DATE_LANGUAGE = FRENCH;

-- display the current system date
SELECT TO_CHAR(SYSDATE, 'Day:Dd Month yyyy') FROM DUAL;

The output from the example should be similar to the following, depending on the current system date:


TO_CHAR(SYSDATE,'DAY:DDMON
--------------------------
Jeudi   :06 Octobre   2005

The default date format uses the month abbreviations determined by the NLS_DATE_LANGUAGE parameter. For example, if the default date format is DD-MON-YYYY and NLS_DATE_LANGUAGE = FRENCH, then insert a date as follows:

INSERT INTO table_name VALUES ('12-Févr.-1997');


See Also:

Oracle Database SQL Reference for information about date format models

Time Formats

Different time formats are shown in Table: Examples of Time Formats.

Examples of Time Formats

Country Description Example

Estonia

hh24:mi:ss

13:50:23

Germany

hh24:mi:ss

13:50:23

China

hh24:mi:ss

13:50:23

UK

hh24:mi:ss

13:50:23

US

hh:mi:ssxff am

1:50:23.555 PM


This section describes the following parameters:

NLS_TIMESTAMP_FORMAT Parameter

The NLS_TIMESTAMP_FORMAT parameter defines the default date format for the TIMESTAMP and TIMESTAMP WITH LOCAL TIME ZONE datatypes. The NLS_TERRITORY parameter determines the default value of NLS_TIMESTAMP_FORMAT. The value of NLS_TIMESTAMP_FORMAT can be any valid datetime format model.

The following example shows a value for NLS_TIMESTAMP_FORMAT:

NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH:MI:SS.FF'

NLS_TIMESTAMP_TZ_FORMAT Parameter

The NLS_TIMESTAMP_TZ_FORMAT parameter defines the default date format for the TIMESTAMP and TIMESTAMP WITH LOCAL TIME ZONE datatypes. It is used with the TO_CHAR and TO_TIMESTAMP_TZ functions. The NLS_TERRITORY parameter determines the default value of the NLS_TIMESTAMP_TZ_FORMAT parameter. The value of NLS_TIMESTAMP_TZ_FORMAT can be any valid datetime format model.

The format value must be surrounded by quotation marks. For example:

NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH:MI:SS.FF TZH:TZM'

In Example: Setting NLS_TIMESTAMP_TZ_FORMAT the TO_TIMESTAMP_TZ function uses the format value that was specified for NLS_TIMESTAMP_TZ_FORMAT.

Setting NLS_TIMESTAMP_TZ_FORMAT

-- display August 20, 2005 using the format of NLS_TIMPSTAMP_TZ_FORMAT
SELECT TO_TIMESTAMP_TZ('2005-08-20, 05:00:00.55 America/Los_Angeles', 
  'yyyy-mm-dd hh:mi:ss.ff TZR') "TIMESTAMP_TZ Format" FROM DUAL;

The output from the example should be similar to the following:


TIMESTAMP_TZ Format
--------------------------------------------------------
20-AUG-05 05.00.00.550000000 AM AMERICA/LOS_ANGELES