Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Date Calculation

Former Member
0 Likes
414

Hi All,

Can someone let me know how to add or substract the days for a given date?

My requirement is as follows,

If the given date is 18.09.2007 then i have to substract 30 days from this. the output should be 19.08.2007.

and, for adding 90 days, if the given date is 18.09.2007, the output should be 17.12.2007.

i.e., the application should consider if any month is having 31 days.

regards,

sailesh

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
395

This is built into the date data type, so it is all handled by the ABAP envirnoment, simply subtract and add to the date. It works.

data: 30_days_ago type sy-datum.
data: 90_days_ahead type sy-datum.

30_days_ago = sy-datum - 30.

90_days_ahead = sy-datum + 90.

Works across months, years, and even handles leap years.

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
396

This is built into the date data type, so it is all handled by the ABAP envirnoment, simply subtract and add to the date. It works.

data: 30_days_ago type sy-datum.
data: 90_days_ahead type sy-datum.

30_days_ago = sy-datum - 30.

90_days_ahead = sy-datum + 90.

Works across months, years, and even handles leap years.

Regards,

Rich Heilman

Read only

ferry_lianto
Active Contributor
0 Likes
395

Hi,

You can also use FM RP_CALC_DATE_IN_INTERVAL.

Regards,

Ferry Lianto

Read only

0 Likes
395

Thanks.