Make sure that timezone is set correctly in your php.ini file, or use the date_default_timezone_set() function. Here you can find list of valid timezones.
Example code:
<?php
date_default_timezone_set('America/Los_Angeles');
if (time() < strtotime("11/25/2014 11:20PM")):
?>
<p>Show me!!!</p>
<?php endif; ?>
Thread Starter
ghp123
(@ghp123)
Wouldn’t it take the same time zone as in the settings from WordPress?
Where are you trying to add that code? To a page through your WordPress page editor, or inserting it in a PHP file?
Thread Starter
ghp123
(@ghp123)
I put the code in the single.php file so that i can have message show up under my posts.
Thread Starter
ghp123
(@ghp123)
The strange thing is that it kind of works but not as i want it.
I would like to stop showing after a curtain time but i can’t get that to happen.
I believe that you’ve changed the date string to your desired date. What date exactly do you want the text to stop showing?
Thread Starter
ghp123
(@ghp123)
Sure i know that i have to change the date and time 🙂
But lets say i want it to show till november 27 at 3pm
then to me the code should be
<?php
date_default_timezone_set(‘America/Los_Angeles’);
if (time() < strtotime(“11/27/2014 3:00PM”)):
?>
<p>Show me!!!</p>
<?php endif; ?>
and this will show me the text BUT at 3PM nothing changes so after the text is still there.
if you’re talking about today, maybe you should change the year to 2013 🙂
Thread Starter
ghp123
(@ghp123)
Yeah what shall i say……..
I should have been able to figure this out myself.
Now i feel really stupid but at least now it works.
Thanks
That’s probably because time travel hasn’t been invented yet 😉 (an attempt at humor there).
Your script seems to be set for next year 11/27/2014
Try 2013, and it should work.
**EDIT** Didn’t see the other posts until after I submitted mine. Now I wish time travel was invented…note to self – work on time travel.