WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] action when in time range (11 posts)

  1. ghp123
    Member
    Posted 1 year ago #

    Hi,

    I am trying to show a curtain text for a limited time and found this code

    <?php if (time() < strtotime("11/25/2014 11:20PM")): ?>
    <FONT color="red" size=3><B>
    Hello show me this text
    </B></FONT>

    <?php endif; ?>

    but it does not work :(

    I am not very smart with php or coding so i wonder if i am missing something.

  2. Theme And Simple
    Member
    Posted 1 year ago #

    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; ?>
  3. ghp123
    Member
    Posted 1 year ago #

    Wouldn’t it take the same time zone as in the settings from WordPress?

  4. Scott
    Member
    Posted 1 year ago #

    Where are you trying to add that code? To a page through your WordPress page editor, or inserting it in a PHP file?

  5. ghp123
    Member
    Posted 1 year ago #

    I put the code in the single.php file so that i can have message show up under my posts.

  6. ghp123
    Member
    Posted 1 year ago #

    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.

  7. Theme And Simple
    Member
    Posted 1 year ago #

    I believe that you've changed the date string to your desired date. What date exactly do you want the text to stop showing?

  8. ghp123
    Member
    Posted 1 year ago #

    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.

  9. Theme And Simple
    Member
    Posted 1 year ago #

    if you're talking about today, maybe you should change the year to 2013 :)

  10. ghp123
    Member
    Posted 1 year ago #

    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

  11. Scott
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags