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

substractin the dates

Former Member
0 Likes
509

Dear All,

there are two dated l_date1 and l_date2.

i want find out the difference between these dates in days.

dif = l_date1 - l_date2 works fine if l_date1 > l_date2 but if l_date2 > l_date1 then direct substraction is not giving the proper answere.In this case i want minus symbol if l_date2 > l_date1.

How to get this.

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
466

Hi ..

This code is working fine .. plz check

<b>parameters: pd1 type sy-datum, pd2 type sy-datum.

data d type i.

d = pd1 - pd2.

write: d.</b>

reward if helpful.

Dear All,

there are two dated l_date1 and l_date2.

i want find out the difference between these dates in days.

dif = l_date1 - l_date2 works fine if l_date1 > l_date2 but if l_date2 > l_date1 then direct substraction is not giving the proper answere.In this case i want minus symbol if l_date2 > l_date1.

How to get this.

2 REPLIES 2
Read only

Former Member
0 Likes
466

Use this code.

IF date1 > date2.
  diff = date1 - date2.
ELSE.
  diff = -1 * ( date2 - date1 ).
ENDIF.

Read only

varma_narayana
Active Contributor
0 Likes
467

Hi ..

This code is working fine .. plz check

<b>parameters: pd1 type sy-datum, pd2 type sy-datum.

data d type i.

d = pd1 - pd2.

write: d.</b>

reward if helpful.