<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB"><title>Comments on PHP DateDiff Function - AddedBytes.com</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/" /><link rel="self" type="application/xml" href="http://www.addedbytes.com/article/php-datediff-function/comments/atom/" /><subtitle>Latest comments on PHP DateDiff Function on AddedBytes.com</subtitle><author><name>Dave Child</name></author><updated>2004-04-20T13:53:00Z</updated><id>tag:addedbytes.com,2004:51</id><!-- ckey="76C662BB" --><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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!</summary><id>tag:addedbytes.com,2009:111179</id><published>2009-06-05T22:26:51+01:00</published><updated>2009-06-05T22:26:51Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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)</summary><id>tag:addedbytes.com,2009:111148</id><published>2009-06-03T04:08:53+01:00</published><updated>2009-06-03T04:08:53Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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</summary><id>tag:addedbytes.com,2009:111133</id><published>2009-06-01T21:01:02+01:00</published><updated>2009-06-01T21:01:02Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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;
</summary><id>tag:addedbytes.com,2009:111131</id><published>2009-06-01T15:49:20+01:00</published><updated>2009-06-01T15:49:20Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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.</summary><id>tag:addedbytes.com,2009:109918</id><published>2009-03-26T13:31:42+00:00</published><updated>2009-03-26T13:31:42Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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!!!</summary><id>tag:addedbytes.com,2009:109768</id><published>2009-03-21T10:05:49+00:00</published><updated>2009-03-21T10:05:49Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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;</summary><id>tag:addedbytes.com,2009:108828</id><published>2009-02-18T21:16:57+00:00</published><updated>2009-02-18T21:16:57Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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;
</summary><id>tag:addedbytes.com,2009:108138</id><published>2009-01-13T17:00:47+00:00</published><updated>2009-01-13T17:00:47Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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.</summary><id>tag:addedbytes.com,2008:107558</id><published>2008-12-16T06:20:58+00:00</published><updated>2008-12-16T06:20:58Z</updated></entry><entry><title>Comment on PHP DateDiff Function</title><link rel="alternate" type="text/html" href="http://www.addedbytes.com/article/php-datediff-function/comments/" /><summary type="text">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</summary><id>tag:addedbytes.com,2008:105790</id><published>2008-10-22T11:10:37+01:00</published><updated>2008-10-22T11:10:37Z</updated></entry></feed>