note 58591 deleted from function.strtotime by aidan
| From: | aidan@php.net | Date: | Wed, 09 Nov 2005 06:11:33 +0000 |
| Subject: | note 58591 deleted from function.strtotime by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98286@lists.php.net to get a copy of this message | ||
Note Submitter: roger - info<at>videosims<dot>com
Reason: useless
----
This is a modification of websafe<at>partybitchez<dot>org function that calculated the
number of complete MONTHS between two dates. I needed one for number of DAYS between two dates(in my
case I needed DAYS counting for the time a client submits an order to the due date they enter in my
order form.
here is the php
<?
function count_days($start_date, $end_date) {
# Returns whole-day-count between two dates
# usage
# count_days("1978-02-18", "2028-08-12");
#
$start_date_unixtimestamp = strtotime($start_date);
$start_date_day = date("d", $start_date_unixtimestamp);
$end_date_unixtimestamp = strtotime($end_date);
$end_date_day = date("d", $end_date_unixtimestamp);
$calculated_date_unixtimestamp = $start_date_unixtimestamp;
$counter=0;
while ($calculated_date_unixtimestamp < $end_date_unixtimestamp)
{
$counter++;
$calculated_date_unixtimestamp = strtotime($start_date . " +{$counter} days");
}
#
if ( ($counter==1) && ($end_date_day==$start_date_day)) $counter=($counter-1);
return $counter;
}
echo count_days("2005-02-18", "2005-02-20");
?>