Business systems live on calendar days: hire dates, invoice dates, effective dates. DATE is Db2’s type for a year-month-day value—not a clock time, and not a free-form string you hope is valid. This page covers internal format and range, literals, common functions, and host-variable conversion pitfalls.
A DATE is a three-part value—year, month, and day—designating a calendar day using the Gregorian calendar model Db2 assumes from year 1 onward. Years run from 0001 to 9999. Months are 1–12. Days are 1–28/29/30/31 depending on the month and leap year rules.
| Item | Value |
|---|---|
| Parts | Year, month, day |
| Range | 0001-01-01 to 9999-12-31 |
| Internal length | 4 bytes |
| Typical external length | 10 characters (unless local date exit) |
Internally, Db2 stores a date as a 4-byte string of packed decimal digits: two bytes for the year, one for the month, one for the day. That compact form is not what COBOL usually holds in Working-Storage. When you SELECT a DATE into a host variable, Db2 converts to an external string—commonly 10 bytes (for example YYYY-MM-DD style) unless a local date exit extends formats up to much longer strings.
123456CREATE TABLE HR.EMPLOYEE ( EMPNO CHAR(6) NOT NULL, HIREDATE DATE NOT NULL, BIRTHDATE DATE, PRIMARY KEY (EMPNO) );
You do not type a “binary DATE constant” in SQL the way you type an integer. Date constants are character strings in recognized formats, or ANSI-style typed constants:
123456INSERT INTO HR.EMPLOYEE (EMPNO, HIREDATE, BIRTHDATE) VALUES ('000150', DATE '2005-05-01', '1980-12-15'); SELECT EMPNO, HIREDATE FROM HR.EMPLOYEE WHERE HIREDATE >= DATE '2000-01-01';
Exact accepted string formats (ISO, USA, EUR, JIS, local) depend on your subsystem and application defaults. Prefer unambiguous ISO-style DATE 'YYYY-MM-DD' forms in portable SQL. The dedicated literals page walks format tables in more depth.
CURRENT DATE is a special register: each time the statement runs, Db2 supplies the current date. Use it for “as of today” defaults and comparisons—not as a substitute for auditing a business event time (that often needs TIMESTAMP).
1234567SELECT EMPNO FROM HR.EMPLOYEE WHERE HIREDATE = CURRENT DATE; UPDATE HR.EMPLOYEE SET HIREDATE = CURRENT DATE WHERE EMPNO = '000150';
| Name | Role |
|---|---|
| CURRENT DATE | Special register: today’s date when SQL runs |
| YEAR / MONTH / DAY | Extract integer parts from a date |
| CHAR(date) | String representation for display or CHAR hosts |
| DATE(expression) | Convert compatible values to DATE |
| + / − durations | Add or subtract days, months, years with labeled durations |
12345678910SELECT EMPNO, YEAR(HIREDATE) AS HIRE_YEAR, MONTH(HIREDATE) AS HIRE_MONTH, DAY(HIREDATE) AS HIRE_DAY, CHAR(HIREDATE) AS HIRE_CHAR FROM HR.EMPLOYEE; -- Labeled duration arithmetic (add one month): SELECT EMPNO, HIREDATE + 1 MONTH AS PROBATION_END FROM HR.EMPLOYEE;
Date arithmetic with durations is powerful and slightly subtle around month-ends (what is January 31 plus one month?). Read IBM rules when building billing cycles. For formatting beyond CHAR’s defaults, shops also use exits or formatting functions depending on version and standards.
MM/DD/YYYY while Db2 expects another style → SQLCODE conversion errorsA robust pattern: keep columns as DATE, move values through well-known string formats at the edges, and centralize formatting in SQL functions or a thin conversion layer—not scattered PIC clauses with conflicting assumptions.
1234-- Prefer typed dates in predicates when possible: WHERE HIREDATE BETWEEN DATE '2020-01-01' AND DATE '2020-12-31' -- Rather than hoping a CHAR column sorts and validates as a calendar
A DATE is a sticker with only the day on the calendar—year, month, and day—like “birthday” or “first day of school.” It does not say what time the party starts (that is TIME or TIMESTAMP). Db2 keeps a tiny packed code inside, but when it talks to your program it usually writes the date as readable text such as 2024-03-15.
1. What does a Db2 DATE value represent?
2. What is the documented DATE range?
3. How many bytes is DATE stored in internally?
4. What does CURRENT DATE return?
5. Why can COBOL host variables for DATE be tricky?