Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Time script

Featured Replies

Hi,

 

I'm currently working on a Wordpress site for a radio show and I'm trying to write a PHP script which will display text when the show is on air (Fridays 2-4pm). I've just about got the time part but I don't know how to make it display on specific Fridays as the show is not broadcast every week (e.g. no broadcast next week, Christmas Day!). I don't mind updating the script each year with the new broadcast dates if that helps.

 

Here's what I've got so far:

 

$time = date(H);

if ($time <14 ¦¦ $time > 16)
{
echo "On Air";
}
else
{
echo "Not On Air";
}

 

Thanks in advance,

Sam

Hi Sam,

Firstly you need to get the comparison correct.

It should be:

if (($time >13) && ($time < 16)){ print stuff);}

 

Then using the date() function, do a comparison of dates stored in your database.

  • Author

Can you give me an example of how I would use the date function to pick specific Fridays?

You could..

...have an array of any exclusions you want, and then display "on air" for non-exclusions...

 

<?php
$exclusions = array(
"25 December 2009"
);


//default message to "Not On Air"
$message = "Not On Air";

//check for Friday
if(date("l") == "Friday") {
//then check the time
$time = date(H);
if ($time >= 14 ¦¦ $time < 16) {
//finally make sure today's not excluded
if(!in_array(date("d F Y"),$exclusions) {
$message = "On Air";
} //end of exclusion check
} //end of time check
} //end of day check

//print out the message
echo $message;

?>

 

The formatting is a bit bad because I can't indent on here, but you get the point!

 

Any dates exclusions should be in the form:

<2 digit date><space><full month name><space><4 digit year>

 

PS: Your original script will work on any day, my version makes sure that it's Fridays only!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.