Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was trying to improve Christopher Pickslay's answer. </p> <p>I made this function that returns and object with most of the properties from the original <code>DateInterval</code> object. </p> <p>There is no "days" property, because it seems to be <a href="https://bugs.php.net/bug.php?id=51184" rel="nofollow">some bug</a> in my test server (it always return 6015) . </p> <p>Also, I am assuming every month has 30 days, which is definitely not precise, but may help. </p> <pre><code>function dateTimeDiff($date1, $date2) { $alt_diff = new stdClass(); $alt_diff-&gt;y = floor(abs($date1-&gt;format('U') - $date2-&gt;format('U')) / (60*60*24*365)); $alt_diff-&gt;m = floor((floor(abs($date1-&gt;format('U') - $date2-&gt;format('U')) / (60*60*24)) - ($alt_diff-&gt;y * 365))/30); $alt_diff-&gt;d = floor(floor(abs($date1-&gt;format('U') - $date2-&gt;format('U')) / (60*60*24)) - ($alt_diff-&gt;y * 365) - ($alt_diff-&gt;m * 30)); $alt_diff-&gt;h = floor( floor(abs($date1-&gt;format('U') - $date2-&gt;format('U')) / (60*60)) - ($alt_diff-&gt;y * 365*24) - ($alt_diff-&gt;m * 30 * 24 ) - ($alt_diff-&gt;d * 24) ); $alt_diff-&gt;i = floor( floor(abs($date1-&gt;format('U') - $date2-&gt;format('U')) / (60)) - ($alt_diff-&gt;y * 365*24*60) - ($alt_diff-&gt;m * 30 * 24 *60) - ($alt_diff-&gt;d * 24 * 60) - ($alt_diff-&gt;h * 60) ); $alt_diff-&gt;s = floor( floor(abs($date1-&gt;format('U') - $date2-&gt;format('U'))) - ($alt_diff-&gt;y * 365*24*60*60) - ($alt_diff-&gt;m * 30 * 24 *60*60) - ($alt_diff-&gt;d * 24 * 60*60) - ($alt_diff-&gt;h * 60*60) - ($alt_diff-&gt;i * 60) ); $alt_diff-&gt;invert = (($date1-&gt;format('U') - $date2-&gt;format('U')) &gt; 0)? 0 : 1 ; return $alt_diff; } </code></pre>
    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.
    2. VO
      singulars
      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