Date and Time Literals
Date and time literals specify ANSI compliant date/time values. There are four types of date and time literals:
• Date
• Time
• Timestamp
• Interval
Date and time literals can be assigned to the corresponding date and time data type without using an explicit conversion function. The value is coded as a quoted string, but is automatically converted to the appropriate internal value.
Date Literals
Literals of the ANSI date type have the following format:
DATE 'date_value'
date_value
Defines a date in the format yyyy-mm-dd.
Note: The II_DATE_FORMAT setting has no impact on the processing of date literals.
Examples:
DATE '2012-05-29'
DATE '1998-10-08'
DATE '2000-11-29'
Time Literals
Literals of the ANSI time type have the following format:
TIME 'time_value'
time_value
Defines a time value in the format hh:mm:ss, optionally followed by .fff (fractions of seconds) and also optionally followed by ±hh:mm, the time zone offset.
Examples:
TIME '11:11:00'
TIME '18:05:23.425364'
TIME '5:23:00-5:00'
TIME '18:05:23.4253+08:00'
Timestamp Literals
Literals of the ANSI timestamp type have the following format:
TIMESTAMP 'timestamp_value'
timestamp_value
Consists of a date value and a time value separated by a single space. The time value can contain optional fractions of seconds, time zone offset, or both.
Examples:
TIMESTAMP '2012-05-29 10:30:00.000-04:00'
TIMESTAMP '1918-11-11 11:11:00'
Interval Literals
Literals of the ANSI interval type have the following format:
INTERVAL '[sign]interval_value' interval_qualifier
sign
Indicates a positive (+) or negative (-). The default is +.
interval_value
Consists of:
A year to month interval value in the format: year-mm (for example: '25-7') or
A day to second interval value in the format: dddd... hh:mm:ss[.fffffffff] (for example: '15 5:10:27.4325')
interval_qualifier
Qualifies the interval as a year to month or a day to second. The interval_qualifier has the following format:
leading field [TO trailing field]
Valid values for leading field and trailing field in order of precedence are:
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND [(p)].
The leading field cannot have lower precedence than the trailing field.
The precision value on the SECOND field indicates the number of digits allowed in the fractional part of that field.
Examples:
INTERVAL '5-7' year to month
INTERVAL '-0-11' year to month
INTERVAL '+24 12:10:5.1234' day to second
INTERVAL '124' year
INTERVAL '12' month
INTERVAL '18' day
INTERVAL '10' hour
INTERVAL '34' minute
INTERVAL '20.23456789' second (9)
INTERVAL '8-11' year to month
INTERVAL '12 10' day to hour
INTERVAL '12 10:20' day to minute
INTERVAL '121 10:15:23.123456' day to second(6)