<?xml version="1.0"?><rss version="2.0"><channel><title>Comments on PHP DateDiff Function - AddedBytes.com</title><link>http://www.addedbytes.com/article/php-datediff-function/</link><description>Latest comments on PHP DateDiff Function on AddedBytes.com</description><!-- ckey="76C662BB" --><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Sharla Hansen ( &lt;a href="http://www.wonderfulproject.com"&gt;http://www.wonderfulproject.com&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;Works well for me!  Thanks!</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Ahmad Ridwan ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;I am his(its first using direct query in its(the mysql database, isn't it mysql there is function of datediff to lessen or adds according to our desire.&lt;br /&gt;
&lt;br /&gt;
But in php simply so complicated like this.. &lt;br /&gt;
&lt;br /&gt;
are there quicker, a few, and easy to be understood.&lt;br /&gt;
&lt;br /&gt;
in mysql, example datediff(date of actually, date of comparison, number of less or in adding)</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Crispin ( &lt;a href="http://www.myenergyusage.org"&gt;http://www.myenergyusage.org&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;Brilliant - thanks</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by David ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
    function Difference( $From, $To ) {&lt;br /&gt;
        $Date1Array = explode( &quot;-&quot;, $From );&lt;br /&gt;
        $Date2Array = explode( &quot;-&quot;, $To );&lt;br /&gt;
        $Date1Greg  = gregoriantojd( $Date1Array[1], $Date1Array[2], $Date1Array[0] );&lt;br /&gt;
        $Date2Greg  = gregoriantojd( $Date2Array[1], $Date2Array[2], $Date2Array[0] );&lt;br /&gt;
        return $Date2Greg - $Date1Greg;&lt;br /&gt;
    }&lt;br /&gt;
    $DaysDiff = Difference( &quot;1985-06-01&quot;, &quot;2009-06-01&quot; );&lt;br /&gt;
    $Done = false;&lt;br /&gt;
    $Years = 0;&lt;br /&gt;
    $Days  = $DaysDiff;&lt;br /&gt;
    while ( !$Done ) {&lt;br /&gt;
        if ( $Days &gt; 365 ) {&lt;br /&gt;
            $Days  = $Days - 365;&lt;br /&gt;
            $Years = $Years + 1;&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
            $Done = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    $Leap = $Years % 4;&lt;br /&gt;
    $Leap = ( $Years - $Leap ) / 4;&lt;br /&gt;
    $Days = $Days - $Leap;&lt;br /&gt;
   &lt;br /&gt;
    echo $Years . &quot; &quot; . $Days;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Solves the problem, at least the one i had. Use strtotime() to work out months from $Days if you need to.&lt;br /&gt;
</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Thomas Dilts ( &lt;a href="http://www.chaniel.se"&gt;http://www.chaniel.se&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;Just wanted to say thanks for the datediff.  The normal date functions in php just didn't do it for me but yours worked great.</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Sumesh ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;Don't trust on 'mktime'&lt;br /&gt;
According to http://in2.php.net/mktime&lt;br /&gt;
&lt;br /&gt;
&quot;the range of valid years was limited to 1970 through 2038. &quot;&lt;br /&gt;
&lt;br /&gt;
It wont work if the year is beyond 2038!!!</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Gabor Balazs ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;This algorithm doesn't give you the exact difference.&lt;br /&gt;
A simple code to get the exact age of someone from it's birth date:&lt;br /&gt;
$date_of_birth='20-04-1978';&lt;br /&gt;
$t=strtotime($date_of_birth);&lt;br /&gt;
if(date(&quot;Y&quot;)&gt;date(&quot;Y&quot;,$t)) &lt;br /&gt;
 {&lt;br /&gt;
    $age=date(&quot;Y&quot;)-date(&quot;Y&quot;,$t);&lt;br /&gt;
    if(date(&quot;m&quot;)&lt;date(&quot;m&quot;,$t)) &lt;br /&gt;
        $age--;&lt;br /&gt;
    else&lt;br /&gt;
       if(date(&quot;m&quot;)==date(&quot;m&quot;,$t) and date(&quot;d&quot;)&lt;date(&quot;d&quot;,$t)) &lt;br /&gt;
	$age--;&lt;br /&gt;
  }&lt;br /&gt;
  else &lt;br /&gt;
       $age=0;</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by Christian S ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;is it better or not to floor the time to the &quot;difference resolution&quot; before doing this difference ? like =&gt;&lt;br /&gt;
&lt;br /&gt;
function datediff($interval, $datefrom, $dateto) &lt;br /&gt;
{&lt;br /&gt;
    // IMPORTANT : $dateto and $datefrom in time format&lt;br /&gt;
	switch($interval) {&lt;br /&gt;
		case &quot;d&quot;: // Number of full days&lt;br /&gt;
			$datediff = floor($dateto/86400) - floor($datefrom/86400); // Difference in days&lt;br /&gt;
		break;&lt;br /&gt;
		&lt;br /&gt;
		case &quot;h&quot;: // Number of full hours&lt;br /&gt;
			$datediff = floor($dateto/3600) - floor($datefrom/3600); // Difference in hours&lt;br /&gt;
		break;&lt;br /&gt;
&lt;br /&gt;
		case &quot;n&quot;: // Number of full minutes&lt;br /&gt;
			$datediff = floor($dateto/60) - floor($datefrom/60); // Difference in minutes&lt;br /&gt;
		break;&lt;br /&gt;
&lt;br /&gt;
		default: // Number of full seconds (default)&lt;br /&gt;
			$datediff = $dateto - $datefrom; // Difference in seconds&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
	return $datediff;&lt;br /&gt;
}&lt;br /&gt;
</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by kitty ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;how to work if the dates are in the format dd/mm/yyyy.</description></item><item><title>Comment on PHP DateDiff Function</title><link>http://www.addedbytes.com/article/php-datediff-function/comments/</link><guid>http://www.addedbytes.com/article/php-datediff-function/comments/</guid><description>Comment by khaild ( &lt;a href=""&gt;&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;wow so many comments, here goes another comment...&lt;br /&gt;
&lt;br /&gt;
thanks for bearing so many comments !!!! :D</description></item></channel></rss>