note 68946 deleted from function.time by bobby

From: Date: Wed, 18 Oct 2006 14:57:30 +0000
Subject: note 68946 deleted from function.time by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118690@lists.php.net to get a copy of this message
Note Submitter: leibwaechter at web dot de ---- I have written a function to check if the current date is between two another dates. So e.g. if you want to check if it is christmas time, you can call isBetweenDates(1,12,26,12) <?php function isBetweenDates($day1,$month1,$day2,$month2) { if ($day1 < 1 || $day1 > 31 || $day2 < 1 || $day2 > 31 || $month1 < 1 || $month1 > 12 || $month2 < 1 || $month2 > 12) return false; $year1 = date("Y"); $year2 = $year1; if (($month2 < $month1) || ($month2 == $month1 && $day2 < $day1)) $year2 += 1; if ($month2 < $month1 && $month1 > date("n")) { $year1 -= 1; $year2 -= 1; } $date1 = mktime(0,0,0,$month1,$day1,$year1); $date2 = mktime(23,0,0,$month2,$day2,$year2); $currentDate = mktime(1,0,0,date("n"),date("j"),date("Y")); if ($date1 <= $currentDate && $date2 >= $currentDate) return true; else return false; } ?>

« previous php.notes (#118690) next »