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

Subtracting 2 dates

Former Member
0 Likes
971

Hi,

I have to dates e.g 20090510 and 20090407. when I subtract them together I wanna know how many days are they apart by. in this example they are 33 days apart.

Can you please assist me.

Regards,

B

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
944

u should supstract variables that are type DATS.

for example:

days = date1 - date2.

days can be string type variable.

7 REPLIES 7
Read only

Former Member
0 Likes
945

u should supstract variables that are type DATS.

for example:

days = date1 - date2.

days can be string type variable.

Read only

Former Member
0 Likes
944

Hi

use FM DAYS_BETWEEN_TWO_DATES

thses will aso help you

LEAP_DAYS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES

RELATION_BETWEEN_TWO_DATES

Thanks

Edited by: jeevitha krishnaraj on Apr 7, 2009 2:49 PM

Read only

Former Member
0 Likes
944

HI,

Check for this Fm HR_99S_INTERVAL_BETWEEN_DATES

or

data l_date1 type sy-datum value '20090510'.
data l_date2 type sy-datum value '20090407'.
data l_date3 type i.

l_date3 = l_date1 - l_date2.
write: l_date3.

Read only

Former Member
0 Likes
944

All you have to do is declare two variables of type D and pass on these values to them. Declare another variable of type I and pass the subtracted value into it.

DATA:

w_highdate type D,

w_lowdate type D,

w_difference type I.

w_highdate = '20090510'.

w_lowdate = '20090407'.

w_difference = w_highdate - w_lowdate.

Read only

Former Member
0 Likes
944

try with the FM given below:

SD_DATETIME_DIFFERENCE

Give the difference in Days and Time for 2 dates

With luck,

Pritam.

Read only

faisalatsap
Active Contributor
0 Likes
944

Hi, Beatrice.

Please Search Before Posting Basic Queries

Best Regards,

Faisal

Read only

Former Member
0 Likes
944

Hi,

Please check on this code... this works for sure

parameters :
   p_date1 type sy-datum,
   p_date2 type sy-datum.

data : w_diff type i.

start-of-selection.
if p_date2 > p_date1.
w_diff = p_date2 - p_date1.
else.
w_diff = p_date1 - p_date2.
endif.

end-of-selection.
write w_diff.

Regards,

Siddarth