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!

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.

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;
 }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.