<?php
/*Skrypt pochodzi z książki "PHP. 101 praktycznych skryptów"
  autor: Marcin Lis                    http://marcinlis.com*/

function dateDiff($str)
{
  if(isSet($_GET['year1'])) $year1 = $_GET['year1'];
  else $year1 = "";

  if(isSet($_GET['year2'])) $year2 = $_GET['year2'];
  else $year2 = "";

  if(isSet($_GET['month1'])) $month1 = $_GET['month1'];
  else $month1 = "";

  if(isSet($_GET['month2'])) $month2 = $_GET['month2'];
  else $month2 = "";

  if(isSet($_GET['day1'])) $day1 = $_GET['day1'];
  else $day1 = "";

  if(isSet($_GET['day2'])) $day2 = $_GET['day2'];
  else $day2 = "";

  $time1 = mktime(0, 0, 0, $month1, $day1, $year1);
  $time2 = mktime(0, 0, 0, $month2, $day2, $year2);
  $time = $time2 - $time1;
  $count = ceil($time / 86400);
  if($count < 0) $count = -$count;

  $arr1 = array("%y1", "%y2", "%m1", "%m2", "%d1", "%d2", "%c");
  $arr2 = array($year1, $year2, $month1, $month2, $day1, $day2, $count);
  $str = str_replace($arr1, $arr2, $str);

  return $str;
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title>Daty</title>
</head>
<body>
<div>
<?php
$str = "Obliczona różnica dni pomiędzy %y1-%m1-%d1, a ";
$str .= "%y2-%m2-%d2 wynosi %c dni.";
echo dateDiff($str);
?>
</div>
</body>
</html>
