Thursday, November 26, 2009

Date and time arithmetics with interval

-- Add five years to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '5' year FROM dual;

-- Add five months to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '5' month
FROM dual;

-- Add five days to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '5' DAY
FROM dual;

-- Add five hours to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '5' hour
FROM dual;

-- Add five hours and 10 minutes to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '5:10' hour to minute
FROM dual;

-- Add 10 minutes to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '10' MINUTE
FROM dual;

-- Add 10 minutes and 30 seconds to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '10:30' MINUTE TO SECOND
FROM dual;

-- Add 30 seconds to current_timestamp
SELECT current_timestamp,current_timestamp + INTERVAL '30' SECOND
FROM dual;

No comments:

Post a Comment