0

Hi,

I have a range of start and end dates return from database in while loop
i need to find, how many of them are continuing.

The example return data;

Array ( [start_date] => 2014-09-22 [end_date] => 2014-09-28 )
Array ( [start_date] => 2014-09-15 [end_date] => 2014-09-21 )
Array ( [start_date] => 2014-09-08 [end_date] => 2014-09-14 )
Array ( [start_date] => 2015-04-06 [end_date] => 2015-04-12 )
Array ( [start_date] => 2015-03-30 [end_date] => 2015-04-05 )
Array ( [start_date] => 2015-04-01 [end_date] => 2015-04-06 )
Array ( [start_date] => 2015-04-01 [end_date] => 2015-04-07 )
Array ( [start_date] => 2015-04-01 [end_date] => 2015-04-07 ) 

expected to find;

Array ( [start_date] => **2014-09-22** [end_date] => 2014-09-28 )
Array ( [start_date] => 2014-09-15 [end_date] => **2014-09-21** )

As the end date of bottom is 2014-09-21 and the next is 2014-09-22 so the dates are continuing without any gaps.
If i find n number of continuing i need to do something.

Could anybody help?

Thank you!

2
Contributors
2
Replies
24
Views
2 Years
Discussion Span
Last Post by kadriirdak
0

Sort your list by start date, then the end date of row N should be one less then the start date of row N+1.

0

Thanks Pritaeas I solved the issue;

while ($row = pg_fetch_row($sql)) {
        $res[] = $row;
       }
foreach($res AS $index=>$res1){
  $one_day_extra = date('Y-m-d',strtotime(@$res[$index+1][1] . "+1 days"));
  if ($res1[0] != $one_day_extra){ // stop the result if no more continuing rows
  break;
 }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.