INTERVAL DAY TO SECOND
A day-to-second interval measures elapsed time: 2 days, 4 hours, 30 minutes. It is what you want for durations, and every engine except Oracle and PostgreSQL makes you fake it.
- Family
- Dates & times
- Missing in
- None of the five
- Gotchas
- 5 listed
Engine by engine
Elapsed time down to fractional seconds. Oracle's INTERVAL DAY TO SECOND takes 11 bytes, PostgreSQL reuses its 16-byte INTERVAL, and the rest store seconds as integers or lean on TIME.
| 引擎 | 類型 | 儲存 | 備註 |
|---|---|---|---|
| SQL Server |
TIME
|
3 to 5 bytes | TIME(7) works as a duration only up to 23:59:59.9999999; larger spans need DATEDIFF or an integer of seconds. |
| PostgreSQL |
INTERVAL
|
16 bytes | interval '2 days 04:30:00'; microsecond precision with separate days and microseconds fields. |
| MySQL |
TIME
|
3 bytes plus fractional | TIME's -838:59:59 to 838:59:59 range makes it a signed duration; beyond 838 hours, store seconds in BIGINT. |
| SQLite |
INTEGER
|
1 to 8 bytes | Store elapsed seconds or milliseconds and format on display; no interval arithmetic beyond date modifiers. |
| Oracle |
INTERVAL DAY TO SECOND
|
11 bytes | INTERVAL '2 04:30:00' DAY TO SECOND; day precision defaults to 2 digits, up to 9, with up to 9 fractional-second digits. |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- SQL Server's TIME is a clock time capped at 24 hours. Using it for durations works only inside one day, and negative durations are impossible - use DATEDIFF results instead.
- MySQL's TIME goes the other way: it is effectively a signed interval of up to 838 hours, so a 'time of day' column can legally hold -12:30:00.
- Oracle's default day precision is 2 digits, so a 100-day interval overflows until you declare INTERVAL '100 0:00:00' DAY(3) TO SECOND.
- PostgreSQL's single INTERVAL mixes both families: interval '1 day' and interval '24 hours' compare equal, but adding them across a DST change in a timestamptz gives different results.
- ISO SQL forbids mixing the two interval families in one value; if you need both, that is two columns, not one.
Common questions
How do I store a duration in SQL Server?
Below 24 hours, TIME(7) works. Otherwise store the total in seconds (BIGINT) or use DATEDIFF between start and end columns - SQL Server has no INTERVAL type.
How many bytes is INTERVAL DAY TO SECOND?
11 bytes in Oracle and 16 bytes for PostgreSQL's combined INTERVAL. Integer-second emulation costs 4 to 8 bytes elsewhere.
What is the difference between MySQL TIME and an interval?
MySQL TIME behaves like a signed interval (up to 838 hours) rather than a clock time, which is unusual: in SQL Server and PostgreSQL, TIME is strictly time-of-day.
Map a type to the other four engines
The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.