<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Calculate users age with PHP</title>
	<atom:link href="http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php</link>
	<description>Random technology, photos and life</description>
	<lastBuildDate>Fri, 07 Oct 2011 17:09:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha</generator>
	<item>
		<title>By: León</title>
		<link>http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php/comment-page-1#comment-33220</link>
		<dc:creator>León</dc:creator>
		<pubDate>Tue, 12 Jul 2011 19:33:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielkassner.com/?p=184#comment-33220</guid>
		<description>I&#039;m sorry. I think the &quot;less than&quot; symbol is messing up the post. I&#039;ll try one last time and if it doesn&#039;t work I&#039;ll just give up.

The first two lines of the code I posted originally should be:

if($days &lt; 0) {
$fakeStartDateString = $s-&gt;format(&#039;Y&#039;).&quot;-&quot;.($e-&gt;format(&#039;m&#039;)-1).&quot;-&quot;.$s-&gt;format(&#039;d&#039;);

Sorry for flooding your post.</description>
		<content:encoded><![CDATA[<p>I&#8217;m sorry. I think the &#8220;less than&#8221; symbol is messing up the post. I&#8217;ll try one last time and if it doesn&#8217;t work I&#8217;ll just give up.</p>
<p>The first two lines of the code I posted originally should be:</p>
<p>if($days &lt; 0) {<br />
$fakeStartDateString = $s-&gt;format(&#8216;Y&#8217;).&#8221;-&#8221;.($e-&gt;format(&#8216;m&#8217;)-1).&#8221;-&#8221;.$s-&gt;format(&#8216;d&#8217;);</p>
<p>Sorry for flooding your post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: León</title>
		<link>http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php/comment-page-1#comment-33218</link>
		<dc:creator>León</dc:creator>
		<pubDate>Tue, 12 Jul 2011 19:31:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielkassner.com/?p=184#comment-33218</guid>
		<description>Again.

if ($days format(&#039;Y&#039;).&quot;-&quot;.($e-&gt;format(&#039;m&#039;)-1).&quot;-&quot;.$s-&gt;format(&#039;d&#039;);</description>
		<content:encoded><![CDATA[<p>Again.</p>
<p>if ($days format(&#8216;Y&#8217;).&#8221;-&#8221;.($e-&gt;format(&#8216;m&#8217;)-1).&#8221;-&#8221;.$s-&gt;format(&#8216;d&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: León</title>
		<link>http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php/comment-page-1#comment-33217</link>
		<dc:creator>León</dc:creator>
		<pubDate>Tue, 12 Jul 2011 19:30:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielkassner.com/?p=184#comment-33217</guid>
		<description>Something messed up my last post. The first two lines of code should be:


if($days format(&#039;Y&#039;).&quot;-&quot;.($e-&gt;format(&#039;m&#039;)-1).&quot;-&quot;.$s-&gt;format(&#039;d&#039;);
</description>
		<content:encoded><![CDATA[<p>Something messed up my last post. The first two lines of code should be:</p>
<p>if($days format(&#8216;Y&#8217;).&#8221;-&#8221;.($e-&gt;format(&#8216;m&#8217;)-1).&#8221;-&#8221;.$s-&gt;format(&#8216;d&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: León</title>
		<link>http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php/comment-page-1#comment-33216</link>
		<dc:creator>León</dc:creator>
		<pubDate>Tue, 12 Jul 2011 19:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielkassner.com/?p=184#comment-33216</guid>
		<description>Daniel,

Thanks for posting your function. After using it with several different birth dates I found that the days were not being calculated correctly. The problem was the correction of negatives days, which substracts the start date day from the total number of days in the start date month, when they should be subsctracted from the last completed month (end date month - 1).

This is what I did:

&lt;code&gt;
		// We cannot have negative days
		// Calculate how many days are in the startdate month // Not the startdate month, but the last completed month (end date month - 1)
		// subtract the startdate day and add 1 // Not necessary to add 1
		// Then add back in the day of the enddate
		// Subtract 1 month
		if ($days format(&#039;Y&#039;).&quot;-&quot;.($e-&gt;format(&#039;m&#039;)-1).&quot;-&quot;.$s-&gt;format(&#039;d&#039;);
			$fakeStartDate = new DateTime($fakeStartDateString);
			$days = $fakeStartDate-&gt;format(&#039;t&#039;)-$s-&gt;format(&#039;d&#039;);
			//$days = $s-&gt;format(&#039;t&#039;)-$s-&gt;format(&#039;d&#039;);//+1;
			$days += $e-&gt;format(&#039;d&#039;);
			$months--;
		}
&lt;/code&gt;

It now works perfectly fine.

I hope someone finds this useful.

Greetings,

León Glz.
Mexico</description>
		<content:encoded><![CDATA[<p>Daniel,</p>
<p>Thanks for posting your function. After using it with several different birth dates I found that the days were not being calculated correctly. The problem was the correction of negatives days, which substracts the start date day from the total number of days in the start date month, when they should be subsctracted from the last completed month (end date month &#8211; 1).</p>
<p>This is what I did:</p>
<p><code><br />
		// We cannot have negative days<br />
		// Calculate how many days are in the startdate month // Not the startdate month, but the last completed month (end date month - 1)<br />
		// subtract the startdate day and add 1 // Not necessary to add 1<br />
		// Then add back in the day of the enddate<br />
		// Subtract 1 month<br />
		if ($days format('Y')."-".($e-&gt;format('m')-1)."-".$s-&gt;format('d');<br />
			$fakeStartDate = new DateTime($fakeStartDateString);<br />
			$days = $fakeStartDate-&gt;format('t')-$s-&gt;format('d');<br />
			//$days = $s-&gt;format('t')-$s-&gt;format('d');//+1;<br />
			$days += $e-&gt;format('d');<br />
			$months--;<br />
		}<br />
</code></p>
<p>It now works perfectly fine.</p>
<p>I hope someone finds this useful.</p>
<p>Greetings,</p>
<p>León Glz.<br />
Mexico</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Piotr</title>
		<link>http://www.danielkassner.com/2010/01/19/calculate-users-age-with-php/comment-page-1#comment-16555</link>
		<dc:creator>Piotr</dc:creator>
		<pubDate>Tue, 08 Feb 2011 12:09:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielkassner.com/?p=184#comment-16555</guid>
		<description>Thanks for this great script!

It is exactly what I needed to calculate the exact difference between 2 dates.
You saved me a lot of time!</description>
		<content:encoded><![CDATA[<p>Thanks for this great script!</p>
<p>It is exactly what I needed to calculate the exact difference between 2 dates.<br />
You saved me a lot of time!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

