Specify the TIMESTAMP datatype as follows: It also stores fractional seconds, which are not stored by the DATE datatype. It stores year, month, day, hour, minute, and second values. The TIMESTAMP datatype is an extension of the DATE datatype. Otherwise, Oracle may not return the query results you expect. You can use the TRUNC (date) SQL function to ensure that the time fields are set to midnight, or you can make the query a test of greater than or less than ( =, or >) instead of equality or inequality ( = or !=). If your queries use a date format without a time portion, then you must ensure that the time fields in the DATE column are set to midnight. Oracle DATE columns always contain fields for both date and time. If you specify a date value without a date, then the default date is the first day of the current month. If you specify a date value without a time component, then the default time is midnight. Oracle automatically converts character values that are in the default date format into date values when they are used in date expressions. The specification for NLS_DATE_LANGUAGE is included because ' DEC' is not a valid value for MON in all locales.
The date format in the example includes a two-digit number for the day of the month, an abbreviation of the month name, the last two digits of the year, and a 24-hour time designation. The default date format for an Oracle date value is derived from the NLS_DATE_FORMAT and NLS_DATE_LANGUAGE initialization parameters. The following is an example of an ANSI date literal:Īlternatively, you can specify an Oracle date value as shown in the following example: For each DATE value, Oracle stores the following information: century, year, month, date, hour, minute, and second.Ĭonverting a character or numeric value to a date value with the TO_DATE functionĪ date can be specified as an ANSI date literal or as an Oracle date value.Īn ANSI date literal contains no time portion and must be specified in exactly the following format: Although date and time information can be represented in both character and number datatypes, the DATE datatype has special associated properties. The DATE datatype stores date and time information. The following sections describe the datetime datatypes and interval datatypes in more detail: TIMESTAMP WITH LOCAL TIME ZONE does not store time zone information internally, but you can see local time zone information in SQL output if the TZH:TZM or TZR TZD format elements are specified. TIMESTAMP WITH TIME ZONE also includes these fields:
The fields that apply to all Oracle datetime and interval datatypes are: The values of these fields determine the value of the datatype. Values of interval datatypes are sometimes called intervals.īoth datetimes and intervals are made up of fields. The interval datatypes are INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND. Values of datetime datatypes are sometimes called datetimes.
The datetime datatypes are DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE.