2 added 306 characters in body; added 45 characters in body
source | link

Try the date_diff() / DateTime::diff() function in PHP:

// Object-oriented style.
$datetime1 = new DateTime( $post->post_date );
$datetime2 = new DateTime(); // current date
$interval = $datetime1->diff( $datetime2 );
echo $interval->format( '%a days old' );

// .. or procedural style.
$datetime1 = date_create( $post->post_date );
$datetime2 = date_create(); // current date
$interval = date_diff( $datetime1, $datetime2 );
echo $interval->format( '%a days old' );

In PHP 5.2.2 or later, you can compare the date ("ago" vs "later") like so:

if ( $datetime1 < $datetime2 ) {
    echo $interval->format( 'Published %a days ago.' );
} elseif ( $datetime1 > $datetime2 ) {
    echo $interval->format( 'Will be published in %a days later.' );
} else {
    echo 'Published today.';
}

Try the date_diff() / DateTime::diff() function:

// Object-oriented style.
$datetime1 = new DateTime( $post->post_date );
$datetime2 = new DateTime(); // current date
$interval = $datetime1->diff( $datetime2 );
echo $interval->format( '%a days old' );

// .. or procedural style.
$datetime1 = date_create( $post->post_date );
$datetime2 = date_create(); // current date
$interval = date_diff( $datetime1, $datetime2 );
echo $interval->format( '%a days old' );

Try the date_diff() / DateTime::diff() function in PHP:

// Object-oriented style.
$datetime1 = new DateTime( $post->post_date );
$datetime2 = new DateTime(); // current date
$interval = $datetime1->diff( $datetime2 );
echo $interval->format( '%a days old' );

// .. or procedural style.
$datetime1 = date_create( $post->post_date );
$datetime2 = date_create(); // current date
$interval = date_diff( $datetime1, $datetime2 );
echo $interval->format( '%a days old' );

In PHP 5.2.2 or later, you can compare the date ("ago" vs "later") like so:

if ( $datetime1 < $datetime2 ) {
    echo $interval->format( 'Published %a days ago.' );
} elseif ( $datetime1 > $datetime2 ) {
    echo $interval->format( 'Will be published in %a days later.' );
} else {
    echo 'Published today.';
}
1
source | link

Try the date_diff() / DateTime::diff() function:

// Object-oriented style.
$datetime1 = new DateTime( $post->post_date );
$datetime2 = new DateTime(); // current date
$interval = $datetime1->diff( $datetime2 );
echo $interval->format( '%a days old' );

// .. or procedural style.
$datetime1 = date_create( $post->post_date );
$datetime2 = date_create(); // current date
$interval = date_diff( $datetime1, $datetime2 );
echo $interval->format( '%a days old' );