2

In the WPTouch theme, the posting date is displayed in a large bubble. However, posts are added the night before, so the day is behind by one. To fix this, I changed this line:

<?php wptouch_the_time( 'j' ); ?>

to this:

    <?php
            $date = DateTime::createFromFormat('m-d-Y', mysql2date('m-d-Y', $post->post_date));
            $date->modify('+1 day');
            echo $date->format('j');
    ?>

This works, but is crazy ugly. I think there should be a better way to get from mysql date to php DateTime.

Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
bonhoffer
  • 1,421
  • 2
  • 23
  • 38
  • 2
    I'd rather use the correct date in WordPress (by scheduling the post for the next day instead of publishing it directly) – Gerald Schneider Jan 13 '15 at 12:22
  • http://stackoverflow.com/questions/14460518/php-get-tomorrows-date-from-date – j0h Jan 13 '15 at 12:24
  • 1
    Well, the less correct version would be to use `date` and `strtotime`: `echo date('j', strtotime($post->post_date . ' +1 day'));` – h2ooooooo Jan 13 '15 at 12:26

3 Answers3

6

You can use this filter to modify the date before it is given to the theme with the function get_the_date() (which wptouch_the_time() most probably uses to get the date):

add_filter( 'get_the_date', 'modify_get_the_date', 10, 3 );
function modify_get_the_date( $value, $format, $post ) {
    $date = new DateTime( $post->post_date );
    $date->modify( "+1 day" );
    if ( $format == "" )
        $format = get_option( "date_format" );
    return( $date->format( $format ) );
}

That being said, instead of modifying the date when it is read from the database, it would be better to just store the publication date when it is written. You can do this by scheduling posts for the next day, instead of publishing them directly.

Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
1

you can do this

<?php
$date=date_create();
date_modify($date,"+1 month");
echo date_format($date,"Y-m-d");
?>
Mohammad Zaer
  • 638
  • 7
  • 9
0

The way i always do this is using the strtotime method

<?php 
$format = ""; // your date format
$oneDayLater = strtotime("+1 day", strtotime($columnValue));
$out = date($format, $oneDayLater);
?>
Barkermn01
  • 6,781
  • 33
  • 83