note 58591 added to function.strtotime
| From: | roger-info<at>videosims" com | Date: | Wed, 09 Nov 2005 02:43:18 +0000 |
| Subject: | note 58591 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98283@lists.php.net to get a copy of this message | ||
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");
?>
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58591
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58591&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58591&report=yes
Search -- http://master.php.net/manage/user-notes.php