note 52198 added to function.strtotime

From: Date: Sun, 24 Apr 2005 06:22:56 +0000
Subject: note 52198 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-88463@lists.php.net to get a copy of this message
<?php function count_months($start_date, $end_date) { # Returns whole-month-count between two dates # websafe<at>partybitchez<dot>org # usage # count_months("1978-02-18", "2028-08-12"); # $start_date_unixtimestamp = strtotime($start_date); $end_date_unixtimestamp = strtotime($end_date); $calculated_date_unixtimestamp = $start_date_unixtimestamp; $counter=0; while ($calculated_date_unixtimestamp < $end_date_unixtimestamp) { $counter++; $calculated_date_unixtimestamp = strtotime($start_date . " +{$counter} months"); } return $counter; } ?> <?php echo 'The result of count_months("1996-02-18", "2005-11-24") is ' . count_months("1996-02-18", "2005-11-24") . "<br />"; echo 'The result of count_months("2005-04-24", "2005-04-24") is ' . count_months("2005-04-24", "2005-04-24") . "<br />"; echo 'The result of count_months("2005-04-24", "2005-04-25") is ' . count_months("2005-04-24", "2005-04-25") . "<br />"; echo 'The result of count_months("1978-02-18", "2028-08-12") is ' . count_months("1978-02-18", "2028-08-12") . "<br />"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52198 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52198&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52198&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52198&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52198&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52198&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52198&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88463) next »