In Oracle, subtracting one DATE value from another gives you the difference directly in days (as a number), because Oracle stores dates internally as numbers. To get differences in other units, or when working with TIMESTAMP values, you need slightly different approaches.
1. Difference in days (DATE columns)
This returns a numeric value representing the number of days (can include a fractional part if time components differ).
2. Difference in hours, minutes, or seconds Since subtracting two dates gives days, multiply to convert:
3. Difference in months or years
Use the built-in MONTHS_BETWEEN function:
Divide by 12 for an approximate year difference, or use EXTRACT combined with subtraction logic for exact calendar-based year differences.
4. Difference between TIMESTAMP values
Subtracting two TIMESTAMP values returns an INTERVAL DAY TO SECOND literal rather than a plain number:
You can then use EXTRACT to pull out specific components:
5. Using TRUNC for whole-day comparisons If your dates include time components but you only want whole calendar days between them:
Choose the method based on whether you're working with DATE or TIMESTAMP types and the precision of the result you need.