note 27156 added to ref.datetime
| From: | allen at rack1 dot php dot net | Date: | Mon, 25 Nov 2002 16:07:39 +0000 |
| Subject: | note 27156 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39949@lists.php.net to get a copy of this message | ||
A quick snippet to get the number of months between two dates (only need the year and month):
// Get the number of months between the two dates
$count_month = $_POST['month_from']
$count_year = $_POST['year_from']
$months = 0;
while (($count_month != $_POST['month_to']) and ($count_year !=
$_POST['year_to'])) {
$count_month--;
if ($count_month == 0) {
$count_month = 12;
$count_year--;
}
$months++;
}
echo $months;
Obviously, the moneths must be in numerical format.
Allen
--
http://www.php.net/manual/en/ref.datetime.php
http://master.php.net/manage/user-notes.php?action=edit+27156
http://master.php.net/manage/user-notes.php?action=delete+27156
http://master.php.net/manage/user-notes.php?action=reject+27156