php days between two dates

A function to calculate the number of days between two dates

Calculate the number of days between two dates using PHP:

 

// Function
function daysBetween2Dates($start, $end)
{
    $day = 86400;                // Day in seconds
    $sTime = strtotime($start); // Start as time
    $eTime = strtotime($end);     // End as time
    return round(($eTime - $sTime) / $day) + 1;
}

// Print
$start = "2011-03-5";
$end = "2011-03-15";
print daysBetween2Dates($start, $end);

 

That's it!