Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to compare datetime values within an array

Status
Not open for further replies.

77walker

Technical User
Feb 7, 2008
33
US
I am using Crystal XI and I have a list of datetime values that I need to compare. I need help in setting this up and doing the comparison.

For example I have five incidents with datetime values I need to find how many of these are concurrent incidents by comparing the next value with the previous value. So I need to load five incidents into an array then always compare the next value with all previous values to find where there are concurrent values. I only want 5 values in the array and as I go through each record I want to drop off the first value so that I may load in the next value.

Each incident has an alarmdate and lastunitcleardate I need to compare the next record alarmdate to see if it is less than or equal to the datecompleted of the previous record and this needs to be repeated for all five elements within an array.

So my data would look like this:

incident.alarmdate incident.lastunitcleardate
7/10/2013 12:30:14 7/10/2013 12:45:15
7/10/2013 12:35:10 7/10/2013 12:48:20
7/10/2013 12:36:10 7/10/2013 12:59:20
7/10/2013 12:42:10 7/10/2013 12:48:20
7/10/2013 12:45:10 7/10/2013 12:48:20

The comparison would show incident 2 would be concurrent with incident 1 since it's alarmdate is <= incident 1's lastunitcleardate, incident 3 is concurrent with incident 1 & 2 because it's alarmdate is <= incident 1's lastunitcleardate and <= incident 2's lastunitcleardate, etc.

Can someone offer me some help on this? I am stumped. I have been able to load the data into the array, but it just keeps loading element after element without stopping at five elements.
 
If only the successive lines can overlap, then you can just use Next and Previous.

Something like:
if next({incidentdate}) = {incidentdate}
and next({incidenttime}) in {alarmtime} to {cleartime}
then "Overlap"
else ' '

If your incidents can go past midnight, then your comparisons get trickier - but if your fields are date/time then it's iven simpler:

if next({alarmdatetime}) in {alarmdatetime} to {cleardatetime}
then "Overlap"
else ' '
 
This works great. I have loaded up the last five lastunitcleardate into an array, and I need to compare each of the values against the currentfield alarmdate to see if it is concurrent with any of the values within. How would I do that? I know once I can get this nailed down it will make the rest of the report easy.
 
LOCAL NUMBERVAR LOOPCNT := 1;
LOCAL STRINGVAR OVERLAP := ' ';
<PUT YOUR ARRAY HERE> ;
WHILE LOOPCNT <= 5
DO (
IF myarray[LOOPCNT] IN NEXT({begindate}) to NEXT({enddate})
then OVERLAP := 'YES'
ELSE OVERLAP := OVERLAP ;
LOOPCNT := LOOPCNT+1);

LOCAL STRINGVAR OVERLAP
 
Thank you Charly I will test this out and let you know if it works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top