note 25970 deleted from function.strtotime by victor
| From: | victor@php.net | Date: | Sun, 13 Oct 2002 18:18:03 +0000 |
| Subject: | note 25970 deleted from function.strtotime by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-38021@lists.php.net to get a copy of this message | ||
I was trying to find a code to check if a certain date is in a date range, couldn't find one so
I made one.
I'm not the most efficient code writer, so this might not be the best way to do it, but it
seems to be the shortest.
// Date Range
// a# = start date, c# = end date, b# = date to check if it's in the range
function month ($monthnum) {
// Return month name from number.
$months = array(1 => 'January', 'February', 'March',
'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December');
$month = $months[$monthnum];
return $month;
}
function date_in_range ($a1,$a2,$a3,$b1,$b2,$b3,$c1,$c2,$c3) {
$a2 = month($a2);
$b2 = month($b2);
$c2 = month($c2);
$atime = strtotime ("$a1 $a2 $a3");
$btime = strtotime ("$b1 $b2 $b3");
$ctime = strtotime ("$c1 $c2 $c3");
if ($atime <= $btime && $btime <= $ctime) { return 1; }
else { return 0; }
}