Jump to content

How do I get things to show up at certain times only?


Riseykins

Recommended Posts

You need to manipulate the date() function.

 

 

G  24-hour format of an hour without leading zeros  0 through 23

 

This may be helpful as well to check to see if it's day or night:

 

A  Uppercase Ante meridiem and Post meridiem  AM or PM

 

And a numerical representation of the day of the week:

 

w  Numeric representation of the day of the week  0 (for Sunday) through 6 (for Saturday)

you would need a basic IF statement and date() function. here is a basic example:

 

$date = date("m/d/Y")

if($date == "12/23/08")
{
show this image
}
elseif($date == "12/24/08")
{
show this image
}
else
{
nothing to show
}

 

 

look into the date function, it is capable of doing time and days of the week to check against.

Well I am wanting to show an alert on my website at certain times each day. I need it to show up between 2 and 3 am, 10 and 11 am and 2 and 3 pm.

 

I don't really know PHP much at all, so I don't know how to edit much, really. :(

No one is just going to write it for you but I will help give you a start:

 

$time_now = date("H"); \\puts it in 24 hour formate
$

if($time_now == 2 || $time_now == 14) \\if the time is 2 am or pm
{
echo "It is 2 o'clock!";
}
elseif($time_now == 10)
{
echo "It is 10 am!";
}
else
{
echo "it isn't 10 or 2";
}

 

check out this page on php date http://www.tizag.com/phpT/phpdate.php

Could you use a cron job  to change the one picture source?

 

You don't need a cron job.  The only time someone is going to see it is when they get to the site.  So all you need to do is modify ngreenwood's code to fit your needs.

 

Why don't you try it, and if you still can't get it to work, come back with more questions?  Usually if you show some effort we're willing to help a lot more.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.