WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Date Minus 1 Day (6 posts)

  1. hockeyhero4
    Member
    Posted 1 year ago #

    How can I subtract a day from my current date in php?

    Here's how I call the date now:

    <?php the_date('l, F j, Y', '<h2>', '</h2>'); ?>

    So, again, it posts today's date but I want it to post yesterday's date.

    Thanks!

  2. curlybracket
    Member
    Posted 1 year ago #

    You should in that case use plain PHP.
    http://www.php.net/manual/en/function.date.php example 3.

  3. it posts today's date but I want it to post yesterday's date....

    Do you want simply the day before the current day, or do you want the day previous to the post's published date? They're completely different. If you want the latter, you need to take the published date and subtract a day from it with php.

  4. hockeyhero4
    Member
    Posted 1 year ago #

    @curly - I tried that solution and it didn't work for me.

    @songdog - The first option; display day before current date.

  5. <h2><?php echo date('l, F j, Y', strtotime('-1 day')); ?></h2>

  6. hockeyhero4
    Member
    Posted 1 year ago #

    You sir, are a genius.

    Thank you very much, I sincerely appreciate you.

    -Michael

Topic Closed

This topic has been closed to new replies.

About this Topic