Calculate days in between given start date and end date in php -


i have $start_date & $end_date.

i need find out number of days name's of days.

i tried following code snipet :

$start_date = '20-07-2012'; $end_date = '22-07-2012'; $start = strtotime($start_date); $end = strtotime($end_date); $interval = 2; $out=''; $int = 24*60*60*$interval; for($i= $start;$i<= $end; $i += $int ){      echo date('d-m-y',$i).'<br />'; } 

output :

28-11-2014 30-11-2014 

but expected out :

28-11-2014 => friday 30-11-2014 => saturday 

let me know should php code yeild expected output.

   // $array[desc:day count starting w 1][desc: 'date' or 'day'];    // $array[2]['day']; <?php $start = '27-11-2014'; $end = '1-12-2014';     function date_difference($start, $end)     {         $first_date = strtotime($start);         $second_date = strtotime($end);         $offset = $second_date-$first_date;          $result = array();         for($i = 0; $i <= floor($offset/24/60/60); $i++) {             $result[1+$i]['date'] = date('d-m-y', strtotime($start. ' + '.$i.'  days'));             $result[1+$i]['day'] = date('l', strtotime($start. ' + '.$i.' days'));         }         echo '<pre>';         print_r($result);         echo '</pre>';     }     date_difference($start, $end); ?> 

result

array (     [1] => array         (             [date] => 27-11-2014             [day] => thursday         )      [2] => array         (             [date] => 28-11-2014             [day] => friday         )      [3] => array         (             [date] => 29-11-2014             [day] => saturday         )      [4] => array         (             [date] => 30-11-2014             [day] => sunday         )      [5] => array         (             [date] => 01-12-2014             [day] => monday         )  ) 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -