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

Operations with dates

Former Member
0 Likes
891

Hi,

I need to sustract 2 dates and obtain the differece of days.

My question is that if I need to do some convertion first or direct sustract the 2 dates and obtain the result in days?

Ex: 02.03.06 - 31.03.06 = 2

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
833

Hi laura,

1. no need to do anything special.

2. just simply minus.

3. eg.

report abc.

data : d1 type sy-datum,

d2 type sy-datum.

data : diff type i.

d1 = '20060101'.

d2 = '20060331'.

diff = d2 - d1.

write : diff.

regards,

amit m.

6 REPLIES 6
Read only

Former Member
0 Likes
833

Hi Laura,

you don't need to do any convesrion.

data: v_diff_in_days type i.

data: v_date1 like sy-datum value '20060202'.

data: v_date2 like sy-datum value '20060101'.

v_diff_in_days = v_date1 - v_date2.

write: v_diff_in_days.

P.S: the dates that are to be subtracted must be of type sy-datum,If they are not in the internal format, then convert the external format Date into internal format using the FM CONVERT_DATE_TO_INTERNAL and then subtract.

Regards,

Ravi

Read only

Former Member
0 Likes
834

Hi laura,

1. no need to do anything special.

2. just simply minus.

3. eg.

report abc.

data : d1 type sy-datum,

d2 type sy-datum.

data : diff type i.

d1 = '20060101'.

d2 = '20060331'.

diff = d2 - d1.

write : diff.

regards,

amit m.

Read only

0 Likes
833

Thanks!!

Read only

Former Member
0 Likes
833

Hi,

you can directly substarct .

data: date1 like sy-datum,
      datt2 like sy-datum.
      
date1 = sy-datum.
date2 = sy-datum - 7.

diff = date1 - date2.

Regards

vijay

Read only

Former Member
0 Likes
833
hi laura,

  directly u can subtract

REPORT  YCHATEST                                .

data : date1 like sy-datum,
       date2 like sy-datum,
       dif type i.


date1 = '20060403'.
date2 = '20060401'.

dif = date1 - date2.

       write : / dif.
Read only

Former Member
0 Likes
833

Hi,

Pls do refer this link too.

Hope its helpful for you.

Best Regards,

Anjali