I am using a function (found it on the web) that calculates the time that has passed until now. I am passing two parameters: post date and current date. it will return years, months, days, hours, minutes OR seconds. it uses PHP 5.3's date diff function which won't do in version 5.2 :(
function pluralize( $zaehler, $inhalt ) {
return trim($zaehler . ( ( $zaehler == 1 ) ? ( " $inhalt" ) : ( " ${inhalt}s" ) )." ago");}function ago($datetime, $datetime_post){
$interval = date_create($datetime_post)->diff( date_create($datetime) );
if ( $interval->y >= 1 ) return pluralize( $interval->y, 'year' );
if ( $interval->m >= 1 ) return pluralize( $interval->m, 'month' );
if ( $interval->d >= 1 ) return pluralize( $interval->d, 'day' );
if ( $interval->h >= 1 ) return pluralize( $interval->h, 'hour' );
if ( $interval->i >= 1 ) return pluralize( $interval->i, 'minute' );
if ( $interval->s >= 1 ) return pluralize( $interval->s, 'second' );}
example:
$post_date_time = "01/01/2012 11:30:22";
$current_date_time = "02/02/2012 07:35:41";
echo ago($current_date_time, $post_date_time);
will output:
1 month
Now I need a equivalent function "ago" that would just do the same, depending on the $interval object.
thank you so much
Additional Info: None of the provided solutions actually did what I was looking for. I have to improve my explaining, sorry. At the end, I need only the $interval object to be having this:
object(DateInterval)#3 (8) { ["y"]=> int(0) ["m"]=> int(1) ["d"]=> int(0) ["h"]=> int(20) ["i"]=> int(5) ["s"]=> int(19) ["invert"]=> int(0) ["days"]=> int(6015) }
The no need to change so many things.