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

Comparing date ranges.

Former Member
0 Likes
2,195

Hi ,

Need your guys advice how to compare two date ranges,

As my code snippet show below, those date can not be compare even Date1 is within the range of Date2 logically...

Any guide and insight i appreciate it alot.

Thanks

.
RANGES : date1 FOR p0001-begda,
         date2 FOR p0001-endda.

date1-sign = 'I'.
date1-option = 'BT'.
date1-low = '20110101'.
date1-high = '20110808'.
APPEND date1.

date2-sign = 'I'.
date2-option = 'BT'.
date2-low = '20110101'.
date2-high = '20110808'.
APPEND date2.

IF date1 IN date2 .

  WRITE:/ 'with in date range'.
  SKIP 2.
ENDIF.

.

5 REPLIES 5
Read only

Former Member
0 Likes
1,135

Hi,

Change the code like this..


if date1-low GE  date2-low and date1-low LE date2-high.
WRITE:/ 'with in date range'.
  SKIP 2.
else.
write: / 'not in the range'.
endif.

Regards,

Dhina..

Read only

0 Likes
1,135

For comparing single date:

if date1-LOW GE date2-low AND date1-LOW LE date2-high.

...............

endif.

for comparing range of dates.

if date1-LOW GE date2-low AND date1-HIGH LE date2-high.

...........

endif.

Read only

Former Member
0 Likes
1,135

Hi

Please find below FM.

U can give begindate and enddate then u get the differences.

HR_99S_INTERVAL_BETWEEN_DATES

Thanks$ Regards.

MURALII

Read only

Former Member
0 Likes
1,135

Hi,

I think only single values can be compared with ranges and not the entire range.

Instead loop at the first range and check if the dates lies in between the other range.

loop at date1.

if date1-low in date2 and date1-high in date2.

*your coding.

else.

*coding

endif.

endloop.

Regards,

Srini.

Read only

koolspy_ultimate
Active Contributor
0 Likes
1,135

try the following


RANGES : date1 FOR p0001-begda,
         date2 FOR p0001-endda.
 
date1-sign = 'I'.
date1-option = 'BT'.
date1-low = '20110101'.
date1-high = '20110808'.
APPEND date1.
 
date2-sign = 'I'.
date2-option = 'BT'.
date2-low = '20110101'.
date2-high = '20110808'.
APPEND date2.
 

use any one


if date1-low GE  date2-low and date1-high LE date2-high.
or
if date1-low in date2-low and date1-high in date2-high.
 

 WRITE:/ 'with in date range'.
else.
write: / 'out of date range'.
ENDIF. 

or

use this fm to calculate the date range HR_99S_INTERVAL_BETWEEN_DATES

here if the result is greater that the actual range then write: out of date range

else if the result is less than or equal to actual range then write: with in range.

NOTE: for this second method actual range refers to the difference of dates calculated by you manually.

So i suggest try the first code.

hope it solves your purpose.

thanks and regards,

koolspy.