Some attributes are “what time of day,” not “which calendar day”—store open time, shift start, or a daily cutoff. TIME is Db2’s type for hours, minutes, and seconds. This page covers range and internal format, literals, precision limits, and conversion gotchas with host variables.
A TIME is a three-part value—hour, minute, and second—for a time of day on a 24-hour clock. Hours run from 0 through 24; minutes and seconds from 0 through 59. The documented range is 00.00.00 through 24.00.00. The value 24.00.00 is Db2’s way of representing the end of the day in this type’s model—something to remember when validating inputs from systems that only allow 00:00:00–23:59:59.
| Item | Value |
|---|---|
| Parts | Hour, minute, second |
| Range | 00.00.00 to 24.00.00 |
| Internal length | 3 bytes |
| Fractional seconds | Not part of TIME—use TIMESTAMP |
Internally, TIME occupies 3 bytes. Like DATE, applications usually see an external character form when fetching into host variables. Catalog and SQLDA lengths differ between internal storage and external string length—DCLGEN follows your install’s local time length settings when they apply.
123456CREATE TABLE APP.STORE_HOURS ( STORE_ID CHAR(4) NOT NULL, OPEN_TIME TIME NOT NULL, CLOSE_TIME TIME NOT NULL, PRIMARY KEY (STORE_ID) );
Time constants are written as strings in recognized formats or as typed constants:
123456INSERT INTO APP.STORE_HOURS (STORE_ID, OPEN_TIME, CLOSE_TIME) VALUES ('S100', TIME '09:00:00', TIME '21:00:00'); SELECT STORE_ID FROM APP.STORE_HOURS WHERE OPEN_TIME <= TIME '10:00:00';
Format variants (with dots, colons, or locale styles) depend on defaults—see the datetime literals page. Prefer explicit TIME '...' forms in shared SQL so readers are not guessing whether '10.30.00' is local-preferred.
CURRENT TIME returns the current time-of-day special register when the statement executes. It does not include the date; pair with CURRENT DATE or use CURRENT TIMESTAMP when you need a full instant.
123SELECT STORE_ID, OPEN_TIME, CLOSE_TIME FROM APP.STORE_HOURS WHERE CURRENT TIME BETWEEN OPEN_TIME AND CLOSE_TIME;
TIME stops at whole seconds. There is no TIME(3) for milliseconds. If a trading system needs subsecond event times, use TIMESTAMP (optionally with an explicit precision) or another design approved by your DBA standards—not a CHAR clock string you parse by hand.
| Type | Holds |
|---|---|
| DATE | Calendar day only |
| TIME | Time of day only |
| TIMESTAMP | Date + time (+ fraction, optional zone) |
Arithmetic with time durations exists, but crossing midnight and combining DATE+TIME into a TIMESTAMP are design moments—spell them out in SQL with TIMESTAMP constructors or explicit casts rather than hoping string concatenation produces valid timestamps.
123456SELECT STORE_ID, HOUR(OPEN_TIME) AS OPEN_HH, MINUTE(OPEN_TIME) AS OPEN_MM, SECOND(OPEN_TIME) AS OPEN_SS, CHAR(OPEN_TIME) AS OPEN_CHAR FROM APP.STORE_HOURS;
Keep columns as TIME, convert at the edges, and document the external format your COBOL/Java services use. When events are “on a day at a time,” a single TIMESTAMP column is often clearer than separate DATE and TIME columns that you must keep in sync.
TIME is the answer to “what time is it on the clock?”—like 3:15:00—without saying which day it is. The clock goes from the start of the day to a special “end of day” mark Db2 allows. If you also need to know the day, or need split seconds, you want a TIMESTAMP sticker instead.
1. What does a Db2 TIME value represent?
2. What is the documented TIME range?
3. How many bytes is TIME stored in internally?
4. Does TIME include fractional seconds?
5. CURRENT TIME is: