Thursday 2 May 2013

Increment date using while loop in php



 $start_date = "2013-01-01";
  $end_date = "2013-01-20";
  $next_date = $start_date;

  while(strtotime($next_date) <= strtotime($end_date))
  {
    echo "$next_date
";
    $next_date = date ("Y-m-d", strtotime("+5 day", strtotime($next_date)));
  }


Ok in for loop?


$start_date = "2013-01-01";
$end_date = "2013-01-25";
$next_date = $start_date;

for($i=0;$i<=(strtotime($next_date) <= strtotime($end_date));$i++)
{
echo "$next_date
";
$next_date = date ("Y-m-d", strtotime("+2 day", strtotime($next_date)));
}





SUM TWO TIMES IN PHP, SUM TWO TIME VALUES IN PHP

echo sum_the_time('01:45:22', '17:27:03');

function sum_the_time($time1, $time2) {
  $times = array($time1, $time2);
  $seconds = 0;
  foreach ($times as $time)
  {
    list($hour,$minute,$second) = explode(':', $time);
    $seconds += $hour*3600;
    $seconds += $minute*60;
    $seconds += $second;
  }
  $hours = floor($seconds/3600);
  $seconds -= $hours*3600;
  $minutes  = floor($seconds/60);
  $seconds -= $minutes*60;
  // return "{$hours}:{$minutes}:{$seconds}";
  return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);