question

dbkid avatar image
dbkid asked

How to add number of days to a date object in oracle?

I am having a requirement that, I need to add 15 days to the joining date.

There is a table called Member. It contains columns Member_Id, Memeber_Name, Join_Date, Validity.

I need to display Validity_Date by adding Validity to Join_Date.

I didn't find any function to do this. Is there any function to add number of days to a date?

Thanks in advance.

oracle
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tariq Rahiman avatar image
Tariq Rahiman answered

CREATE TABLE MEMBER (MEMBER_ID INT, MEMBER_NAME CHAR(10), JOIN_DATE DATE, VALIDITY DATE) go

select to_date(VALIDITY) + interval '15' day from member go

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dbkid avatar image dbkid commented ·
Its very simple and readibility is more. Thanks a lot Tariq Rahiman!
0 Likes 0 ·
BI DWH BALA avatar image BI DWH BALA commented ·
I know about Date Object + number of days (Select sysdate+2 from dual). But I don't know the syntax you have given here. This is some thing new to me. Thank you Tariq Rahiman.
0 Likes 0 ·
Christian13467 avatar image
Christian13467 answered

Adding days to an oracle date is just adding the amount of days as number.

SELECT sysdate + 10 FROM dual; -- adds 10 days to current datetime SELECT sysdate + 1/1440 FROM dual; -- adds 1 minute to current datetime

The syntax given before is adding a interval. Interval is an oracle type to describe timespans. Look here for more information.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.