- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am looking for a script which will allow me to display some text ‘Open Now’ on a certain day and time of the week and ‘Closed’ on the other days. I’m a complete newb in javascript/php so i’m not sure how to even start this, although i have an idea.
Can anyone help me with this one?
Regards.
Here’s an easy example:
if ( date("w") == 5 ) {
echo "Sorry, the internet is closed today!";
}
else {
echo "Open for business!";
}
?>
Explanation: the code first checks if today’s day number of the week (from 1-7), equals 5 (=friday). If that is so, it will show the text Sorry, the internet is closed today. If it isn’t 5, it will show the text Open for business!
Ofcourse, this code can be extended, but it should get you started.
Is it possible to add a time onto that also.
Say 9:00am – 5:30 for ‘X’ days but i’m not sure the on the php syntax for that.
Yep. Add an and to your if statement. Look at the online PHP documentation for date() and format.
So
$datestart = 9
$dateend = 17
If(date(‘G’) >= $datestart && date(‘G’) <= $dateend && date('w') == '5'){ Do what ever }