<?php
  /********* dateDiff() function **********
   * returns Array of Int values for difference between two dates
   * $date1 > $date2 --> positive integers are returned
   * $date1 < $date2 --> negative integers are returned
   *
   * $split recognizes the following:
   *  'yw' = splits up years, weeks and days (default)
   *  'y'  = splits up years and days
   *  'w'  = splits up weeks and days
   *  'd'  = total days
   *
   * examples:
   *  $dif1 = dateDiff() or dateDiff('yw')
   *  $dif2 = dateDiff('y')
   *  $dif3 = dateDiff('w')
   *  $dif4 = dateDiff('d')
   *
   * assuming dateDiff returned 853 days, the above
   * examples would have a print_r output of:
   *  $dif1 == Array( [y] => 2 [w] => 17 [d] => 4 )
   *  $dif2 == Array( [y] => 2 [d] => 123 )
   *  $dif3 == Array( [w] => 121 [d] => 6 )
   *  $dif4 == Array( [d] => 847 )
   *
   * note: [h] (hours), [m] (minutes), [s] (seconds) are always returned as elements of the Array
   */
  function dateDiff($dt1, $dt2, $split='yw') {
   $date1 = (strtotime($dt1) != -1) ? strtotime($dt1) : $dt1;
   $date2 = (strtotime($dt2) != -1) ? strtotime($dt2) : $dt2;
   $dtDiff = $date1 - $date2;
   $totalDays = intval($dtDiff/(24*60*60));
   $totalSecs = $dtDiff-($totalDays*24*60*60);
   $dif['h'] = $h = intval($totalSecs/(60*60));
   $dif['m'] = $m = intval(($totalSecs-($h*60*60))/60);
   $dif['s'] = $totalSecs-($h*60*60)-($m*60);
   // set up array as necessary
   switch($split) {
   case 'yw': # split years-weeks-days
     $dif['y'] = $y = intval($totalDays/365);
     $dif['w'] = $w = intval(($totalDays-($y*365))/7);
     $dif['d'] = $totalDays-($y*365)-($w*7);
     break;
   case 'y': # split years-days
     $dif['y'] = $y = intval($totalDays/365);
     $dif['d'] = $totalDays-($y*365);
     break;
   case 'w': # split weeks-days
     $dif['w'] = $w = intval($totalDays/7);
     $dif['d'] = $totalDays-($w*7);
     break;
   case 'd': # don't split -- total days
     $dif['d'] = $totalDays;
     break;
   default:
     die("Error in dateDiff(). Unrecognized \$split parameter. Valid values are 'yw', 'y', 'w', 'd'. Default is 'yw'.");
   }
   return $dif;
  }

	$d = datediff(strtotime("now"), strtotime("21 march 2005"), 'yw');
	$bar = each($d);
	print_r($bar);


?> 
