Note that there are some explanatory texts on larger screens.

plurals
  1. POphp 5.3 date diff equivalent for PHP <= 5.2 on own function
    primarykey
    data
    text
    <p>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 :(</p> <pre><code>function pluralize( $zaehler, $inhalt ) { return trim($zaehler . ( ( $zaehler == 1 ) ? ( " $inhalt" ) : ( " ${inhalt}s" ) )." ago");}function ago($datetime, $datetime_post){ $interval = date_create($datetime_post)-&gt;diff( date_create($datetime) ); if ( $interval-&gt;y &gt;= 1 ) return pluralize( $interval-&gt;y, 'year' ); if ( $interval-&gt;m &gt;= 1 ) return pluralize( $interval-&gt;m, 'month' ); if ( $interval-&gt;d &gt;= 1 ) return pluralize( $interval-&gt;d, 'day' ); if ( $interval-&gt;h &gt;= 1 ) return pluralize( $interval-&gt;h, 'hour' ); if ( $interval-&gt;i &gt;= 1 ) return pluralize( $interval-&gt;i, 'minute' ); if ( $interval-&gt;s &gt;= 1 ) return pluralize( $interval-&gt;s, 'second' );} </code></pre> <p>example:</p> <pre><code>$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); </code></pre> <p>will output:</p> <pre><code>1 month </code></pre> <p>Now I need a equivalent function "ago" that would just do the same, depending on the $interval object.</p> <p>thank you so much</p> <p>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:</p> <pre><code>object(DateInterval)#3 (8) { ["y"]=&gt; int(0) ["m"]=&gt; int(1) ["d"]=&gt; int(0) ["h"]=&gt; int(20) ["i"]=&gt; int(5) ["s"]=&gt; int(19) ["invert"]=&gt; int(0) ["days"]=&gt; int(6015) } </code></pre> <p>The no need to change so many things.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload