Automated message based on date
Posted: Sat Jul 05, 2008 10:49 am
I am currently using the following code to automatically generate messages for when my business will be closed base don the date of a holiday. This is working fine, but seems inefficient. Is there perhaps a more efficient or concise way to express the same code?
Thanks.
-Bill
Code: Select all
<?php
//set the holidays
$new = "2009-01-01";
$mem = "2009-05-25";
$ind = "2009-07-04";
$lab = "2008-09-01";
$tha = "2008-11-27";
$chr = "2008-12-25";
$todays_date = date("Y-m-d");
//converts to time
$hol_new = strtotime($new);
$hol_mem = strtotime($mem);
$hol_ind = strtotime($ind);
$hol_lab = strtotime($lab);
$hol_tha = strtotime($tha);
$hol_chr = strtotime($chr);
$today = strtotime($todays_date);
//message
$message = "We will be closed<br />";
if ($today <= $hol_new && $today >= $hol_new-7 ) {
echo $message . "New Years Day.";
}
elseif ($today <= $hol_mem && $today >= $hol_mem-7) {
echo $message . "Memorial Day.";
}
elseif ($today <= $hol_ind && $today >= ($ind-7)) {
echo $message . "Independence Day.";
}
elseif ($today <= $hol_lab && $today >= $hol_lab-7) {
echo $message . "Labor Day.";
}
elseif ($today <= $hol_tha && $today >= $hol_tha-7) {
echo $message . "Thanksgiving Day.";
}
elseif ($today <= $hol_chr && $today >= $hol_chr-7) {
echo $message . "Christmas Day.";
}
?>
-Bill