note 68946 added to function.time
| From: | leibwaechter at web dot de | Date: | Wed, 16 Aug 2006 21:35:43 +0000 |
| Subject: | note 68946 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115986@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 80.134.152.133
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- https://master.php.net/note/edit/68946
Del: integrated -- https://master.php.net/note/delete/68946/integrated
Del: useless -- https://master.php.net/note/delete/68946/useless
Del: bad code -- https://master.php.net/note/delete/68946/bad+code
Del: spam -- https://master.php.net/note/delete/68946/spam
Del: non-english -- https://master.php.net/note/delete/68946/non-english
Del: in docs -- https://master.php.net/note/delete/68946/in+docs
Del: other reasons-- https://master.php.net/note/delete/68946
Reject -- https://master.php.net/note/reject/68946
Search -- https://master.php.net/manage/user-notes.php