Finding the difference between 2 dates
<p>I made this and needed some help tweaking it so that it gives the proper outcome</p>

<pre><code>function daysDifference($end){
    //$start = "2007-03-24";
    //$end = "2009-06-26";
    $now = date("Y-m-d");
    $e = (is_string($end) ? strtotime($end) : $end);

    $diff = abs($e - strtotime($now));

    $years = floor($diff / (365 * 60 * 60 * 24));
    $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
    $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24)/ (60 * 60 *24));

    return ($years == 0 ? '' : ($years == 1 ? $years . ' year ' : $years . ' years ')) . ($months == 0 ? '' : ($months == 1 ? $months . ' month ' : $months . ' months ')) . ($days == 0 ? '' : ($days == 1 ? $days . ' day ' : $days . ' days '));
}
</code></pre>

<p><code>$end</code> is being pulled from my database so there is checks to see if its a string or a date already.</p>

<p><code>$e</code> now can be used, but when I tried to subtract <code>$now</code> from <code>$e</code> I get funny results</p>

<p>for instance:</p>

<p><code>$now</code> being today the <code>13th</code> and <code>$e</code> being an end date for a project, it's suppose to give me what I need... right?</p>

<p>Where I'm suppose to get say 12 days remaining, I get 1 year 12 days.</p>

<p>and where <code>$e = 0000-00-00</code> (in case the user didn't input an end date), I get 40 years 10 months and 26 days remaining.</p>

<p>I tried alot of different variations to my calculations but I keep getting nowhere.</p>
