How do I add days to a timestamp? If my timestamp is 01-JAN-2011 11-09-05
and I add 2 days, I want 03-JAN-2011 11-09-05
.
Asked
Active
Viewed 6.3k times
21

Marcellinov
- 311
- 7
- 18

Nadir
- 211
- 1
- 2
- 3
3 Answers
36
select '01-jan-2011 11-09-05' + interval '2' day

Marc B
- 356,200
- 43
- 426
- 500
-
7+1. A more complete Oracle example: SELECT TO_TIMESTAMP('01-jan-2011 11-09-05','DD-Mon-YYYY HH24-MI-SS') + INTERVAL '2' DAY FROM dual; – DCookie May 26 '11 at 18:08
-
Using interval seems better than using `+` because I noticed loss of timezone with the latter. – Antoine Martin Nov 20 '19 at 11:26
4
A completely Oracle-centric solution is to simply add 2 to the timestamp value as the default interval is days for Oracle dates/timestamps:
SELECT TO_TIMESTAMP('01-jan-2011 11-09-05','DD-Mon-YYYY HH24-MI-SS') + 2
FROM dual;

DCookie
- 42,630
- 11
- 83
- 92
1
In a similar case, I used:
SELECT TO_TIMESTAMP('01-jan-2011 11-09-05','DD-Mon-YYYY HH24-MI-SS') + NUMTODSINTERVAL(2, 'DAY')
Because, othewise, the expression is converted to DATE and precission is lost. See: NUMTODSINTERVAL documentation

adcelis
- 66
- 4