Calcola la distanza in giorni tra due date in php

<?
$date_from = '23.11.2004';
$date_to = '07.05.2005';
$date_from_parts = explode('.', $date_from);
$date_to_parts = explode('.', $date_to);

// Calculating the UNIX Timestamp for both dates
$ts_from = mktime(0, 0, 0, $date_from_parts[1], $date_from_parts[0], $date_from_parts[2]);
$ts_to = mktime(0, 0, 0, $date_to_parts[1], $date_to_parts[0], $date_to_parts[2]);

// 86400 = seconds per day
for ($x = $ts_from; $x <= $ts_to; $x += 86400){
$vacation_days[] = date('d.m.Y', $x);
}

for ($i = 0; $i <= count($vacation_days); $i++){
echo $vacation_days[$i]."<br>";
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>