Wordpress Date Code Help

2 replies
I am trying to create a wordpress date code that will display at the top of a post, but I want to backdate it a few days. Traditional Code would look like:


This entry was posted on <?php the_time('F jS, Y') ?>

This entry was posted on August 19, 2010

----

But I want it to backdate say 3 days so it would display August 16, 2010 on August 19, 2010 and then auto update to August 17, 2010 when the date is actually August 20, 2010

Any help is appreciated.
#code #date #wordpress
  • Profile picture of the author Bruce Hearder
    You could use something like the following code to achieve what you want..

    [?php
    $threedaysago = time() - (3 * 24 * 60 * 60);
    // 3 days; 24 hours; 60 mins; 60secs
    echo date('F js Y', $threedaysago );
    ?]

    Note: Change the square brackets to angle brackets, and this should do what you are after..

    Hope this helps

    Bruce
    {{ DiscussionBoard.errors[2493296].message }}
  • Profile picture of the author SteveJohnson
    Easiest is to take advantage of php's strtotime function:

    PHP Code:
    echo date('F jS, Y'strtotime"3 days ago" ) ); 
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2497648].message }}

Trending Topics