The following code works to echo "Open" or "Closed" if time is between 8:15am and 5:30pm. I am trying to make it day specific. How can I incorporate format character 'D' as example, Mon hours 8:15am - 5:30pm .. echo "Open", Sat hours 8:15am - 1:00pm "Open". I want to be able to control echo of Open/Closed by each day and time.
current working code for hours only
<?php
date_default_timezone_set('America/New_York');
$hour = (int) date('Hi');
$open = "yah hoo, we are open";
$closed = "by golly, im closed";
if ($hour >= 0815 && $hour <=1735) {
// between 8:15am and 5:35pm
echo "$open";
} else {
echo "$closed";
}
?>
example of what I am trying to do:
$hour = (int) date('D Hi');
if ($hours >= 0815 && $hour <=1735 && $hour === 'Mon')
{ echo "$open"; }
else { echo "$closed"; }
if ($hours >= 0815 && $hour <=1300 && $hour === 'Sat')
{ echo "$open"; }
else { echo "$closed"; }
another example per The One and Only's answer which looks close to what I am looking for, but this also does not work
<?php
$openDaysArray = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat','Sun');
$thisDate = date('D Hi');
$explode = explode(" ", $thisDate);
$day = $explode[0];
$time = $explode[1];
if (in_array($day, $openDaysArray))
if ($time < 815 || $time > 1730 && $day === 'Mon');
if ($time < 815 || $time > 1730 && $day === 'Tue');
if ($time < 815 || $time > 1730 && $day === 'Wed');
if ($time < 815 || $time > 1730 && $day === 'Thu');
if ($time < 815 || $time > 1730 && $day === 'Fri');
if ($time < 815 || $time > 1730 && $day === 'Sat');
if ($time < 815 || $time > 1730 && $day === 'Sun');
{echo 'Open';}
else {echo 'Closed';}
?>
I'd handle it this way. Set up an array of all your open times. If you know you're closed on Saturday and Sunday, there's really no need to proceed with with checking times at that point, so kill the process there first. Then simply find out what day of the week it is, look up the corresponding opening and closing times in your $hours array, create actual DateTime objects to compare (rather than integers). Then just return the appropriate message.
function getStatus() {
$hours = array(
'Mon' => ['open'=>'08:15', 'close'=>'17:35'],
'Tue' => ['open'=>'08:15', 'close'=>'17:35'],
'Wed' => ['open'=>'08:15', 'close'=>'17:35'],
'Thu' => ['open'=>'08:15', 'close'=>'22:35'],
'Fri' => ['open'=>'08:15', 'close'=>'17:35']
);
$now = new DateTime();
$day = date("D");
if ($day == "Sat" || $day == "Sun") {
return "Sorry we're closed on weekends'.";
}
$openingTime = new DateTime();
$closingTime = new DateTime();
$oArray = explode(":",$hours[$day]['open']);
$cArray = explode(":",$hours[$day]['close']);
$openingTime->setTime($oArray[0],$oArray[1]);
$closingTime->setTime($cArray[0],$cArray[1]);
if ($now >= $openingTime && $now < $closingTime) {
return "Hey We're Open!";
}
return "Sorry folks, park's closed. The moose out front should have told ya.";
}
echo getStatus();
Use a switch statement:
$thisDate = date('D Hi');
$hoursOfOpArray = array("Mon_Open" => "815", "Mon_Close" => "1730", "Tue_Open" => "815", "Tue_Close" => "1730"); //repeat for all days too fill this array
$explode = explode(" ", $thisDate);
$day = $explode[0];
$time = (int)$explode[1];
switch($day) {
case "Sun":
$status = "Closed";
break;
case "Mon":
$status = ($time < $hoursOfOpArray[$day . "_Open"] || $time > $hoursOfOpArray[$day . "_Close"]) ? "Closed" : "Open";
break;
//same as Monday case for all other days
}
echo $status;
This should also work:
echo ($day === 'Sun' || ($time < $hoursOfOpArray[$day . "_Open"]) || ($time > $hoursOfOpArray[$day . "_Close"])) ? "Closed" : "Open";
$o = ['Mon' => [815, 1735], /*and all other days*/'Sat' => [815, 1300]];
echo (date('Hi')>=$o[date('D')][0] && date('Hi')<=$o[date('D')][1]) ? "open": "closed";
Done! And dont ask.
This one works, added remarks to explain as much as possible.
<?php
date_default_timezone_set('America/New_York');
// Runs the function
echo time_str();
function time_str() {
if(IsHoliday())
{
return ClosedHoliday();
}
$dow = date('D'); // Your "now" parameter is implied
// Time in HHMM
$hm = (int)date("Gi");
switch(strtolower($dow)){
case 'mon': //MONDAY adjust hours - can adjust for lunch if needed
if ($hm >= 0 && $hm < 830) return Closed();
if ($hm >= 830 && $hm < 1200) return Open();
if ($hm >= 1200 && $hm < 1300) return Lunch();
if ($hm >= 1300 && $hm < 1730) return Open();
if ($hm >= 1730 && $hm < 2359) return Closed();
break;
case 'tue': //TUESDAY adjust hours
if ($hm >= 830 && $hm < 1730) return Open();
else return Closed();
break;
case 'wed': //WEDNESDAY adjust hours
if ($hm >= 830 && $hm < 1730) return Open();
else return Closed();
break;
case 'thu': //THURSDAY adjust hours
if ($hm >= 830 && $hm < 1730) return Open();
else return Closed();
break;
case 'fri': //FRIDAY adjust hours
if ($hm >= 830 && $hm < 1730) return Open();
else return Closed();
break;
case 'sat': //Saturday adjust hours
return Closed();
break;
case 'sun': //Saturday adjust hours
return Closed();
break;
}
}
// List of holidays
function HolidayList()
{
// Format: 2009/05/11 (year/month/day comma seperated for days)
return array("2016/11/24","2016/12/25");
}
// Function to check if today is a holiday
function IsHoliday()
{
// Retrieves the list of holidays
$holidayList = HolidayList();
// Checks if the date is in the holidaylist - remove Y/ if Holidays are same day each year
if(in_array(date("Y/m/d"),$holidayList))
{
return true;
}else
{
return false;
}
}
// Returns the data when open
function Open()
{
return 'Yes we are Open';
}
// Return the data when closed
function Closed()
{
return 'Sorry We are Closed';
}
// Returns the data when closed due to holiday
function ClosedHoliday()
{
return 'Closed for the Holiday';
}
// Returns if closed for lunch
// if not using hours like Monday - remove all this
// and make 'mon' case hours look like 'tue' case hours
function Lunch()
{
return 'Closed for Lunch';
}
?>
Related
So I have this code that works perfectly:
<?php
$time = date("H");
$timezone = date("e");
if ($time < "13") {
echo "message1";
} else
if ($time >= "13" && $time < "19") {
echo "message2";
} else
if ($time >= "19" && $time < "24") {
echo "message3";
}
?>
The problem is that I can only use hours: 1, 5, 10, 19 and etc.
I need to use minutes as well, eg. 13:30.
I have tried changing to 13:30. Also tried changing to 1350.
But can't make it work.
Need help.
Create a new variable that hold the current minute,
DateTime::format shows us that date("i") gives:
Minutes with leading zeros
With the current hour and minute, you can calculate any time, for example:
<?php
$hour = date("H");
$minute = date("i");
// Between 13:30 and 13:30
if ($hour === 13 && $minute <= 30) {
echo "message1";
}
// Between 13:30 and 19:00
elseif (($hour >= 13 && $minute >= 30) && $hour < 19) {
echo "message2";
}
// After 19:00
else {
echo "message3";
}
?>
I'm using the following code to show opening and closing times throughout the week however on a Tuesday the time to open is at 10:30. It seems to want to sit at 10 or 11. I've tried 10.5 in the PHP variable, but that's not making a change. Any suggestions?
<?php
date_default_timezone_set('Europe/London'); // set it to the right value
$weAreOpen = areWeOpen(date('l'), date('G'));
if($weAreOpen) {
echo 'We are open for business';
} else {
echo 'We are closed';
}
/**
* Test if we're open for business
* #param string $day - day of week (ex: Monday)
* #param string $hour - hour of day (ex: 9)
* #return bool - true if open interval
*/
function areWeOpen($day, $hour) {
$hour = (int)$hour;
switch($day) {
case 'Monday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Tuesday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Wednesday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Thursday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Friday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Saturday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Sunday':
if($hour >= 10 && $hour < 16) {
return true;
}
break;
}
return false;
}
?>
You should read up on what date('G') actually does in the PHP manual for date(). It gives you the hour in an 24 hour format. So, naturally, there can never be a .5 hour.
To check for half hours you can for example get the minutes from here, but in general there is probably a better solution than to check all parts of the clock individually, e.g. checking if the time of the day is lower or greater than something.
You just need to pass minutes as function parameter and use it in if condition like this
<?php
date_default_timezone_set('Europe/London'); // set it to the right value
$weAreOpen = areWeOpen(date('l'), date('G'), date('i'));
if($weAreOpen) {
echo 'We are open for business';
} else {
echo 'We are closed';
}
/**
* Test if we're open for business
* #param string $day - day of week (ex: Monday)
* #param string $hour - hour of day (ex: 9)
* #return bool - true if open interval
*/
function areWeOpen($day, $hour, $minutes) {
$hour = (int)$hour;
switch($day) {
case 'Monday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Tuesday':
if($hour >= 11 && $hour < 21 || ($hour == 10 && $minutes >= 30)) {
return true;
}
break;
case 'Wednesday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Thursday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Friday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Saturday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Sunday':
if($hour >= 10 && $hour < 16) {
return true;
}
break;
}
return false;
}
?>
You should also send the minutes information to your function and check with it.
$weAreOpen = areWeOpen(date('l'), date('G'), date('i'));
...
...
function areWeOpen($day, $hour, $minutes) {
...
// check the minutes value as well
...
}
You need to incorporate minutes and not only hours if you want to react on times like "10:30". Try this:
<?php
date_default_timezone_set('Europe/London'); // set it to the right value
$weAreOpen = areWeOpen(date('l'), date('G'), date('i'));
if($weAreOpen) {
echo 'We are open for business';
} else {
echo 'We are closed';
}
/**
* Test if we're open for business
* #param string $day - day of week (ex: Monday)
* #param string $hour - hour of day (ex: 9)
* #param string $minute - minute (ex: 42)
* #return bool - true if open interval
*/
function areWeOpen($day, $hour, $minute) {
switch($day) {
case 'Monday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Tuesday':
if(($hour + $minute/60) >= 10.5 && $hour < 21) {
return true;
}
break;
case 'Wednesday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Thursday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Friday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Saturday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Sunday':
if($hour >= 10 && $hour < 16) {
return true;
}
break;
}
return false;
}
?>
You cast your variable to an integer in the very first line of your function:
$hour = (int)$hour;
So any information after the hour number will be lost after that.
Removing that line would solve that.
By the way, I don't see any logic in your function that accounts for the Tuesday opening time.
You should probably decide on a format (real time or floats) first and adapt your logic accordingly. I would probably use a DateTime object to store all the information about the moment you are querying about and would give you the possibility to expand the function for holidays, etc..
I would suggest what others already have, you need to include minutes if you want to check against a half hour. Though, I would also simply the rest of the code:
<?php
$weAreOpen = areWeOpen(date('l'), date('G'), date('i'));
if($weAreOpen) {
echo 'We are open for business';
} else {
echo 'We are closed';
}
/**
* Test if we're open for business
* #param string $day - day of week (ex: Monday)
* #param string $hour - hour of day (ex: 9)
* #param int $min - Minute of the hour
* #return bool - true if open interval
*/
function areWeOpen($day, $hour, $min) {
$hour = (int)$hour;
switch($day) {
case 'Monday':
case 'Wednesday':
case 'Thursday':
case 'Friday':
case 'Saturday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Tuesday':
if(($hour >= 11 && $hour < 21) || ($min >= 30 && $hour == 10)) {
return true;
}
break;
case 'Sunday':
if($hour >= 10 && $hour < 16) {
return true;
}
break;
}
return false;
}
?>
I'm trying to make an messages appear on my website when we are open and when the phones are "closed" but I can't seem to get it working.
This is what I have so far (This is my inspiration http://codewalkers.com/c/a/Date-Time-Code/Display-message-according-to-hour-of-day/)
<?php
//Change message of the day
$open = 'We are open for business';
$closed = 'We are closed';
//Get the current time
$current_time = date(G);
//Get the current day
$current_day = date(I);
if ($current_day == "Monday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Monday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Tuesday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Tuesday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Wednesday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Wednesday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Thursday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Thursday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Friday" && $current_time >= 9 && $current_time <= 19) {
echo $open;
}
elseif ($current_day == "Friday" && $current_time >= 19 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Saturday") {
echo $closed;
}
if ($current_day == "Sunday") {
echo $closed;
}
?>
and im getting this error message
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in - on line 7 Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in - on line 9
It would be nice to have some qualified help :)
The qualified help you requested comes in the form of the script below:
Also note that in your code you have to use date('l') - lowercase L.
The list of timezones you can use for date_default_timezone_set() can be found here:
http://php.net/manual/en/timezones.php
date_default_timezone_set('Europe/Amsterdam'); // set it to the right value
$weAreOpen = areWeOpen(date('l'), date('G'));
if($weAreOpen) {
echo 'We are open for business';
} else {
echo 'We are closed';
}
/**
* Test if we're open for business
* #param string $day - day of week (ex: Monday)
* #param string $hour - hour of day (ex: 9)
* #return bool - true if open interval
*/
function areWeOpen($day, $hour) {
$hour = (int)$hour;
switch($day) {
case 'Monday':
case 'Tuesday':
case 'Wednesday':
case 'Thursday':
if($hour >= 9 && $hour < 21) {
return true;
}
break;
case 'Friday':
if($hour >= 9 && $hour < 19) {
return true;
}
break;
}
return false;
}
date() takes a string, and your code could be shorter:
//Change message of the day
$open = 'We are open for business';
$closed = 'We are closed';
$current_time = date('G'); //Get the current time
$current_day = date('w'); //Get the current day
if ($current_day > 0 && $current_day < 6) //Monday to Friday
{
if ($current_time >= 9 && $current_time <= 21 && $current_day != 5) //Monday to Thursday between 9 and 21
echo $open;
else if ($current_time >= 9 && $current_time <= 19 && $current_day == 5) //Friday between 9 and 19
echo $open;
else
echo $closed;
}
else //Saturday and Sunday
echo $closed;
About your warning, open your php.ini and add this block if you don't have it:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Seoul
You can also just add this line at the beginning of your code: date_default_timezone_set('Asia/Seoul');.
See http://php.net/manual/en/timezones.php for the list of supported timezones.
So perhaps this will solve your problem:
//Get the current time
$current_time = date('G');
//Get the current day
$current_day = date('l');//This is lowercase 'L' and NOT 'I' as in "India".
And as far as I know, php date() accepts string as first argument. And the G and L can only work well if you had earlier defined them as constants...
EDIT
Seeing your updated question with the error message, you can try this:
ini_set('date.timezone', 'Africa/Lagos');' //somewhere at the top of your code.
Or else you could place this in you php configuration file (e.g. php.ini in windows):
date.timezone = Africa/Lagos
Then, of course, replace "Africa/Lagos" with the timezone of your choice. And for a list of supported timezones, see here.
try this
<?php
date_default_timezone_set('UTC');
//Change message of the day
$open = 'We are open for business';
$closed = 'We are closed';
//Get the current time
$current_time = date("G");
//Get the current day
$current_day = date("l");
if ($current_day == "Monday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Monday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Tuesday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Tuesday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Wednesday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Wednesday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Thursday" && $current_time >= 9 && $current_time <= 21) {
echo $open;
}
elseif ($current_day == "Thursday" && $current_time >= 21 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Friday" && $current_time >= 9 && $current_time <= 19) {
echo $open;
}
elseif ($current_day == "Friday" && $current_time >= 19 && $current_time <= 9) {
echo $closed;
}
if ($current_day == "Saturday") {
echo $closed;
}
if ($current_day == "Sunday") {
echo $closed;
}
?>
High Season:
April 28 - September 30,
December 27 - January 3
Low Season:
October 1 - December 26,
January 4 - April 27
I gave a date to check: 2014-02-18 and I want to have TRUE or FALSE in case of which season includes it. How to do it regardless of the current year?
Try with simple date comparing:
function is_high_season($date) {
$md = gmdate('m-d', strtotime($date));
return
('03-28' <= $md && $md <= '09-30') ||
('12-27' <= $md && $md <= '12-31') ||
('01-01' <= $md && $md <= '01-03');
}
demo
$day = $d->format('j');
$month = $d->format('n');
if($month == 1 && $day <= 3) {
return 'high';
} elseif $month < 4 || ($month == 4 && $day < 28)) {
return 'low';
} elseif($month == 4 && $day >= 28) {
return 'high';
} elseif($month < 10) {
return 'high';
} elseif($month < 12 || ($month == 12 && $day < 27)) {
return 'low';
} elseif($month == 12 && $day >= 27) {
return 'high';
}
$Date = date('Y-m-d');
$Date=date('Y-m-d', strtotime($Date));;
//echo $Date; // echos today!
$hiDateBegin = date('Y-m-d', strtotime("28/04/2014"));
$hiDateEnd = date('Y-m-d', strtotime("30/09/2014"));
$hiDateBegin2 = date('Y-m-d', strtotime("27/12/2014"));
$hiDateEnd2 = date('Y-m-d', strtotime("03/01/2015"));
$lowDateBegin = date('Y-m-d', strtotime("01/10/2014"));
$lowDateEnd = date('Y-m-d', strtotime("26/12/2014"));
$lowDateBegin2 = date('Y-m-d', strtotime("04/01/2015"));
$lowDateEnd2 = date('Y-m-d', strtotime("27/04/2015"));
if (($Date > $hiDateBegin) && ($Date < $hiDateEnd))
{
echo "is Hi Season";
}
if (($Date > $hiDateBegin2) && ($Date < $hiDateEnd2))
{
echo "is Hi Season";
}
if (($Date > $lowDateBegin) && ($Date < $lowDateEnd))
{
echo "is Low Season";
}
if (($Date > $lowDateBegin2) && ($Date < $lowDateEnd2))
{
echo "is Low Season";
}
else
{
echo "Date doesn't fall in a season!";
}
I'm trying to piece together a php script to output different text depending on what day it is and the time of day.
Example:
On weekdays (mon-fri), I would like to output text according to the following periods of time (24H, server time, UTC):
00:00-08:00: "Lorem ipsum"
08:00-13:00: "dolor sit amet"
13:00-15:00: "Pellentesque habitant"
15:00-15:30: "dolor sit amet"
15:30-24:00: "Lorem ipsum"
On weekends (sat-sun), I would like to output the following text in this time period:
00:00-24:00 "Lorem ipsum"
Can anyone help with a php script to do that?
I've already gotten some help over at the css-tricks forum. They supplied this code:
<?php
$date = strtotime("now");
$hour = date("H", $date);
switch($hour) {
case 00:
case 01:
case 02:
case 03:
case 04:
case 05:
case 06:
case 07:
case 08:
$dets = array("img" => "image1.png", "txt" => "Lorem ipsum");
break;
case 09:
case 10:
case 11:
case 12:
case 13:
$dets = array("img" => "image2.png", "txt" => "dolor sit amet");
break;
case 14:
case 15:
case 16:
$dets = array("img" => "image3.png", "txt" => "Pellentesque habitant");
break;
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
$dets = array("img" => "image1.png", "txt" => "Lorem ipsum");
break;
}
echo "<img src='$dets[img]' alt='$dets[txt]' />";
?>
But it works for all days, and only in full hours. I want to be able to specify per half-hour and on a day to day basis.
Still a php-noob so I'm hoping someone can help me.
Drop the switch statement and use a series of if/else statements. The switch isn't going to give you the granularity without being massively verbose.
<?php
function time_str() {
$dow = date('D'); // Your "now" parameter is implied
if ($dow == 'Sat' || $dow == 'Sun') {
// weekend
return 'Lorum Ipsum';
}
// Time in HHMM format
$hm = (int)date("Gi");
if ($hm >= 0 && $hm < 800) return 'Lorem ipsum';
if ($hm >= 800 && $hm < 1300) return 'dolor sit amet';
if ($hm >= 1300 && $hm < 1500) return ...
if ($hm >= 1500 && $hm < 1530) return ...
if ($hm >= 1530 && $hm < 2359) return ...
}
I also have to point out that your switch statement has an extra case that will never be used - 24. There is no 24th hour; after 23:59, the clock wraps back around to 00:00.
That switch is ugly.
Why not something like:
<?PHP
if (date('l') == 'Saturday' || date('l') == 'Sunday')){
echo 'Lorem ipsum';
}else{ //it's a weekday
if (intval(date('H')) < 8){
echo 'Lorem ipsum';
}elseif(/* another expression */){
echo "something else..
}
}
Thanks for all your suggestions. I had a friend (whos a little better at php than me) look at them, and we came up with this solution.
With this, I am able to specify text for different times of the day, and different days of the week, along with having a list of days with it's very own text.
<?php
date_default_timezone_set('Europe/Copenhagen');
// Runs the function
echo time_str();
function time_str() {
if(IsHoliday())
{
return ClosedHoliday();
}
$dow = date('D'); // Your "now" parameter is implied
if ($dow == 'Sat' || $dow == 'Sun') {
// weekend
return Closed();
}
// Time in HHMM
$hm = (int)date("Gi");
switch(strtolower($dow)){
case 'mon': //MONDAY
if ($hm >= 0 && $hm < 800) return Closed();
if ($hm >= 800 && $hm < 1100) return Open();
if ($hm >= 1100 && $hm < 1500) return OpenDelay();
if ($hm >= 1500 && $hm < 1600) return Open();
if ($hm >= 1600 && $hm < 2359) return Closed();
break;
case 'tue': //TUESDAY
if ($hm >= 0 && $hm < 800) return Closed();
if ($hm >= 800 && $hm < 1100) return Open();
if ($hm >= 1100 && $hm < 1500) return OpenDelay();
if ($hm >= 1500 && $hm < 1600) return Open();
if ($hm >= 1600 && $hm < 2359) return Closed();
break;
case 'wed': //WEDNESDAY
if ($hm >= 0 && $hm < 800) return Closed();
if ($hm >= 800 && $hm < 1100) return Open();
if ($hm >= 1100 && $hm < 1500) return OpenDelay();
if ($hm >= 1500 && $hm < 1600) return Open();
if ($hm >= 1600 && $hm < 2359) return Closed();
break;
case 'thu': //THURSDAY
if ($hm >= 0 && $hm < 800) return Closed();
if ($hm >= 800 && $hm < 1100) return Open();
if ($hm >= 1100 && $hm < 1500) return OpenDelay();
if ($hm >= 1500 && $hm < 1600) return Open();
if ($hm >= 1600 && $hm < 2359) return Closed();
break;
case 'fri': //FRIDAY
if ($hm >= 0 && $hm < 800) return Closed();
if ($hm >= 800 && $hm < 1100) return Open();
if ($hm >= 1100 && $hm < 1500) return OpenDelay();
if ($hm >= 1500 && $hm < 1600) return Open();
if ($hm >= 1600 && $hm < 2359) return Closed();
break;
}
}
// List of holidays
function HolidayList()
{
// Format: 2009/05/11 (comma seperated)
return array("2010/05/04","2009/05/11");
}
// Function to check if today is a holiday
function IsHoliday()
{
// Retrieves the list of holidays
$holidayList = HolidayList();
// Checks if the date is in the holidaylist
if(in_array(date("Y/m/d"),$holidayList))
{
return true;
}else
{
return false;
}
}
// Returns the data when open
function Open()
{
return 'Open';
}
// Return the data when closed
function Closed()
{
return 'Closed';
}
// Returns the data when open but with waiting time
function OpenDelay()
{
return 'Open, but with delay';
}
// Returns the data when closed due to holiday
function ClosedHoliday()
{
return 'Lukket pga. helligdag';
}
?>
$hoursandminutes = date("H:m", $date)
switch ($hoursandminutes)
case "08:15":
//do something,
//be aware though that the string representation 08:15 might actually be 8:15 even in 24h format
I'm sure you can figure out how to go about adding day to day functionallity as well. Read up on the date class.
I am using this, its working, but I would also load some text from an external txt file depending on the day of week.
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META HTTP-EQUIV="refresh" CONTENT="60">
<title>LOUNAS</title>
<style type="text/css">
body {
overflow:hidden;
}
</style>
<script type="text/javascript"><!--
var imlocation = "";
function ImageArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '
}
}
image = new ImageArray(7);
image[0] = 'sunday.jpg';
image[1] = 'monday.jpg';
image[2] = 'tuesday.jpg';
image[3] = 'wednsday.jpg';
image[4] = 'thursday.jpg';
image[5] = 'friday.jpg';
image[6] = 'saturday.jpg';
var currentdate = new Date();
var imagenumber = currentdate.getDay();
document.write('<img src="' + imlocation + image[imagenumber] + '"> style="width:100%;height:100%;" border="0" /');
//--></script></head>
<body bgcolor="#000000">
</body>
</html>