Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just needed that ( unfortunately ) for a WordPress plugin. This I use the function in 2 times. I posted this answer <a href="https://stackoverflow.com/questions/4033224/what-can-use-for-datetimediff-for-php-5-2">here</a>:</p> <ol> <li><p>In my class calling <strong>->diff()</strong> ( my class extends <strong>DateTime</strong>, so <strong><em>$this</em></strong> is the reference <strong>DateTime</strong> )</p> <pre><code>function diff ($secondDate){ $firstDateTimeStamp = $this-&gt;format("U"); $secondDateTimeStamp = $secondDate-&gt;format("U"); $rv = ($secondDateTimeStamp - $firstDateTimeStamp); $di = new DateInterval($rv); return $di; } </code></pre></li> <li><p>Then I recreated a fake DateInterval class ( because DateInterval is only valid in PHP >= 5.3 ) as follows: </p> <pre><code>Class DateInterval { /* Properties */ public $y = 0; public $m = 0; public $d = 0; public $h = 0; public $i = 0; public $s = 0; /* Methods */ public function __construct ( $time_to_convert /** in seconds */) { $FULL_YEAR = 60*60*24*365.25; $FULL_MONTH = 60*60*24*(365.25/12); $FULL_DAY = 60*60*24; $FULL_HOUR = 60*60; $FULL_MINUTE = 60; $FULL_SECOND = 1; // $time_to_convert = 176559; $seconds = 0; $minutes = 0; $hours = 0; $days = 0; $months = 0; $years = 0; while($time_to_convert &gt;= $FULL_YEAR) { $years ++; $time_to_convert = $time_to_convert - $FULL_YEAR; } while($time_to_convert &gt;= $FULL_MONTH) { $months ++; $time_to_convert = $time_to_convert - $FULL_MONTH; } while($time_to_convert &gt;= $FULL_DAY) { $days ++; $time_to_convert = $time_to_convert - $FULL_DAY; } while($time_to_convert &gt;= $FULL_HOUR) { $hours++; $time_to_convert = $time_to_convert - $FULL_HOUR; } while($time_to_convert &gt;= $FULL_MINUTE) { $minutes++; $time_to_convert = $time_to_convert - $FULL_MINUTE; } $seconds = $time_to_convert; // remaining seconds $this-&gt;y = $years; $this-&gt;m = $months; $this-&gt;d = $days; $this-&gt;h = $hours; $this-&gt;i = $minutes; $this-&gt;s = $seconds; } } </code></pre></li> </ol> <p>Hope that helps somebody.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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