Wordpress Date Code Help

by 2 replies
3
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.
#programming #code #date #wordpress
  • 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
  • Easiest is to take advantage of php's strtotime function:

    PHP Code:
    echo date('F jS, Y'strtotime"3 days ago" ) ); 
    • [ 1 ] Thanks

Next Topics on Trending Feed