note 84942 modified in function.date by felipe
| From: | felipe@php.net | Date: | Wed, 06 Aug 2008 22:05:33 +0000 |
| Subject: | note 84942 modified in function.date by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143247@lists.php.net to get a copy of this message | ||
Try this for finding the difference in days between 2 dates/datetimes... take note though,
date_parse requires PHP version 5.1.3 or higher.
<?php
/**
* Finds the difference in days between two calendar dates.
*
* @param Date $startDate
* @param Date $endDate
* @return Int
*/
function dateDiff($startDate, $endDate)
{
// Parse dates for conversion
$startArry = date_parse($startDate);
$endArry = date_parse($endDate);
// Convert dates to Julian Days
$start_date = gregoriantojd($startArry["month"], $startArry["day"],
$startArry["year"]);
$end_date = gregoriantojd($endArry["month"], $endArry["day"],
$endArry["year"]);
// Return difference
return round(($end_date - $start_date), 0);
}
?>
--was--
Try this for finding the difference in days between 2 dates/datetimes... take note though,
date_parse requires PHP version 5.1.3 or higher.
/**
* Finds the difference in days between two calendar dates.
*
* @param Date $startDate
* @param Date $endDate
* @return Int
*/
function dateDiff($startDate, $endDate)
{
// Parse dates for conversion
$startArry = date_parse($startDate);
$endArry = date_parse($endDate);
// Convert dates to Julian Days
$start_date = gregoriantojd($startArry["month"], $startArry["day"],
$startArry["year"]);
$end_date = gregoriantojd($endArry["month"], $endArry["day"],
$endArry["year"]);
// Return difference
return round(($end_date - $start_date), 0);
}
http://php.net/manual/en/function.date.php