note 39297 added to function.date
| From: | thomas dot kaarud at netcom dot no | Date: | Fri, 23 Jan 2004 14:55:58 +0000 |
| Subject: | note 39297 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64067@lists.php.net to get a copy of this message | ||
I needed a function that could help me find out if any given date was a holiday. The array that
contains all holidays add a simple way of making local variations of this function. The function
returns True if the given day is a holiday.
<?
// Input date in format YYYY-MM-DD
function check_for_holiday($date)
{
$year = date('Y',(strtotime($date)));
$maundy_thursday = date("Y-m-d",mktime(0,0,0,3,18+easter_days($year),$year));
$good_friday = date("Y-m-d",mktime(0,0,0,3,19+easter_days($year),$year));
$easter_sunday = date("Y-m-d",mktime(0,0,0,3,21+easter_days($year),$year));
$easter_monday = date("Y-m-d",mktime(0,0,0,3,22+easter_days($year),$year));
$ascension_day = date("Y-m-d",mktime(0,0,0,3,60+easter_days($year),$year));
$whit_sunday = date("Y-m-d",mktime(0,0,0,3,70+easter_days($year),$year));
$whit_monday = date("Y-m-d",mktime(0,0,0,3,71+easter_days($year),$year));
$holiday_array = array("$year-01-01", "$year-12-25", $maundy_thursday,
$good_friday, $easter_sunday, $easter_monday,
$ascension_day, $whit_sunday, $whit_monday );
if (in_array($date, $holiday_array)) return(true); else return(false);
}
if (check_for_holiday($date)) die("$date is a holiday"); else die("$date is not a
holiday");
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39297
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39297&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39297&report=yes
Search -- http://master.php.net/manage/user-notes.php