Business data is full of calendars and clocks: hire dates, cut-off times, audit stamps. In DB2 for z/OS you usually store those values in DATE, TIME, or TIMESTAMP columns—and you write fixed samples as datetime literals. This page shows date literals, time literals, and timestamp literals, including typed ANSI forms and time zones.
A datetime constant is a character string constant written in a format Db2 recognizes as a date, time, or timestamp. Internally Db2 stores datetime types in a special format; on input and output it converts to and from string representations.
You can also use ANSI/ISO-style typed constants that start with the keywords DATE, TIME, or TIMESTAMP followed by a string constant. Those forms make the intended data type obvious to readers and to the SQL parser.
| Type | Meaning | Typed literal example |
|---|---|---|
| DATE | Year, month, day | DATE '2024-03-15' |
| TIME | Hour, minute, second | TIME '14:30:00' |
| TIMESTAMP | Date + time + fractions (± zone) | TIMESTAMP '2024-03-15 14:30:00.123456' |
Prefer real datetime types over storing dates as CHAR or INTEGER. Literals then compare cleanly, date arithmetic works, and invalid calendar values are rejected instead of silently stored as junk strings.
A DATE is a three-part value: year, month, and day, in the range 0001-01-01 through 9999-12-31. Date literals are strings that follow a valid date representation.
1234SELECT * FROM HR.EMPLOYEE WHERE HIREDATE >= DATE '2020-01-01' AND HIREDATE < '2021-01-01';
Rules for the ANSI DATE string-constant form include:
Sites also accept other string styles (USA, EUR, JIS, and related) depending on product rules. For application SQL that travels between environments, ISO-like yyyy-mm-dd is the least ambiguous choice. Display format for SELECT results can still follow installation defaults or CHAR(... format) overrides even when you entered ISO input.
A TIME is a three-part value for hour, minute, and second (range from 00.00.00 through 24.00.00 in Db2’s documented limits). Time literals are valid time strings, optionally written as TIME '...'.
123VALUES TIME '14:30:00'; VALUES TIME '2:30 PM'; VALUES '14.30.00';
Useful rules:
Time-only columns are less common than timestamps in modern designs, but they still appear for schedules (“store opens at…”). Be explicit with 24-hour ISO-style times in interfaces that mix locales.
A TIMESTAMP combines date and time, optionally with fractional seconds and optionally with a time zone. Fractional second digits can range from 0 to 12; that count becomes precision p for TIMESTAMP(p).
123VALUES TIMESTAMP '2024-03-15 14:30:00'; VALUES TIMESTAMP '2024-03-15-14.30.00.123456'; VALUES '2024-03-15T14:30:00.123456789';
Documented timestamp-without-time-zone patterns include combinations of:
Examples of accepted shapes (see SQL Reference tables for the full set):
12345-- Illustrative shapes 'yyyy-mm-dd hh:mm:ss' 'yyyy-mm-dd hh.mm.ss.nnnnnn' 'yyyy-mm-dd-hh.mm.ss' 'yyyy-mm-ddThh:mm:ss.nnnnnnnnnnnn'
Leading blanks are disallowed; trailing blanks may appear. Leading zeros may be omitted from month, day, and hour (and time zone hour); minute and second elements need their leading zeros. Hour 24 is allowed only when minutes, seconds, and fractions are zero.
For TIMESTAMP WITH TIME ZONE, the string includes an offset or UTC designator, for example:
12VALUES TIMESTAMP '2024-03-15 14:30:00+02:00'; VALUES TIMESTAMP '2024-03-15 14:30:00Z';
Without a zone, you get TIMESTAMP WITHOUT TIME ZONE semantics. Mixing zoned and unzoned data in one expression requires care—explicit CAST and clear application rules beat guesswork.
123456INSERT INTO APP.AUDIT_LOG (EVENT_TS, NOTE) VALUES (CURRENT TIMESTAMP, 'row inserted'); SELECT * FROM APP.ORDERS WHERE ORDER_DATE = DATE '2024-01-31';
CURRENT DATE, CURRENT TIME, and CURRENT TIMESTAMP evaluate when the statement runs. Literals are fixed values in the statement text. Use registers for “now,” literals for historical or planned fixed points. CURRENT TIME ZONE is related but answers a different question (session time zone displacement).
A date literal is like writing a birthday on a party invitation: year, month, and day. A time literal is like writing “the party starts at three o’clock.” A timestamp is writing both—“March 15, 2024 at 3:00”—and sometimes how many tiny ticks after the second, and which town’s clock (the time zone). CURRENT TIMESTAMP is looking at the clock on the wall when you mail the invitation. A literal is writing a fixed time that does not change when you look at the wall later.
1. What is a datetime constant in Db2?
2. Which is a valid way to write a date constant?
3. What does TIMESTAMP precision in a literal depend on?
4. How can you include a time zone in a timestamp constant?
5. Are CURRENT DATE / CURRENT TIME the same as literals?