I'm still very new to this but is there a way to control content (text and/or image) using PHP and a specific date? For example I need to add "New Store Hours" to a listing of locations for a client website, however I don't want to have to go back into all of the pages and turn them off after a few weeks. Any help or suggestions would be much appreciated.

5 Years
Discussion Span
Last Post by Marty1963

USe a DB to store times and locations:


store_id (int/3/PK)
store_name (varchar/50)
store_address1 (varchar/100)
store_address1 (varchar/100)
store_address1 (varchar/100)
store_postcode (varchar/8)
store_www (varchar/50)
store_email (varchar/75)
store_tel1 (varchar/16)
active (tinyint/1) - this can decide whether the store is displayed or not

store_id (int/3)
date_id (int/3)
day_no (0-6 = SUN-SAT)
opentime (24hour format)
closetime (24hour format)

(each store-date can have multiple entries e.g. AM opening, PM opening if req'd)

date_id (int/3/PK)
datefrom (date)

This is a simplified relational model. Of course you could use a real date in the times table, but this may be wasteful.

Once you have the data in place, you then insert placeholders in your html for opening and closing times.

When you add new opening and closing times, if you query for the lastest date, then your data should be the most recent.

Hope that's the sort of thing you were looking for.


Thank you Ardav for your fast reply, however I was hoping to manage this without a database. Perhaps I was unclear, there are only one or two stores who change their hours at any given time. All I was after was a snippet of PHP code that would make a "New Hours" image or text not visable after a set period of time. Regards.


DOh! MY apologies - sometimes I read what I want to read - and totally get the wrong end of the stick.

Set a $timeoff variable (date for image to be taken off at the top of the page.

Then compare this against the current time. If ok, show image, if expired don't show it:

$timeoff = '2012-10-09 00:00:00';
$timenow = date('Y-m-d H:i:s');
$showimg = ($timenow >= $timeoff) ? false : true;

Then by your image:

if($showimg)echo '<img src="images/newtimes.png" title="Check out our new times!" />';

Fantastic!! Thank you that was just what I was looking for. I was able to write something that worked, but yours is much cleaner. I really appreciate your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.