daysBetweenDates

<?php

/**
* Calculates the diference in days between two dates.
*
* @param string $start_date Start date (format yyyy-mm-dd)
* @param string $end_date End date (format yyyy-mm-dd)
* @param boolean $include_end_date Include end date in calculation (1 day is added)
*
* @return integer Number of days.
* */
function daysBetweenDates($start_date, $end_date, $include_end_date = false) {

// Timestamp for start date
list($s_year, $s_month, $s_day) = explode("-", $start_date);
$start_date_timestamp = mktime(0, 0, 0, $s_month, $s_day, $s_year);

// Timestamp for end date
list($e_year, $e_month, $e_day) = explode("-", $end_date);
$end_date_timestamp = mktime(0, 0, 0, $e_month, $e_day, $e_year);

// Diference between dates
$diff = ($end_date_timestamp - $start_date_timestamp);
$days = floor($diff / (60 * 60 * 24));

if ($include_end_date)
$days++;

return $days;
}

?>

0 Comments

You must be logged in to post a comment.