<?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: Simple PHP Dates</title>
	<atom:link href="http://mattf.ca/php/simple-php-dates/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattf.ca/php/simple-php-dates/</link>
	<description>Internet Marketing Dundada</description>
	<lastBuildDate>Wed, 21 Jul 2010 16:10:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Riley Pool</title>
		<link>http://mattf.ca/php/simple-php-dates/comment-page-1/#comment-404</link>
		<dc:creator>Riley Pool</dc:creator>
		<pubDate>Fri, 05 Feb 2010 20:18:16 +0000</pubDate>
		<guid isPermaLink="false">http://mattf.ca/?p=101#comment-404</guid>
		<description>Thanks for the code Matt.  I was looking for a simple solution like this the other day.</description>
		<content:encoded><![CDATA[<p>Thanks for the code Matt.  I was looking for a simple solution like this the other day.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Fraser</title>
		<link>http://mattf.ca/php/simple-php-dates/comment-page-1/#comment-311</link>
		<dc:creator>Matt Fraser</dc:creator>
		<pubDate>Thu, 31 Dec 2009 19:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://mattf.ca/?p=101#comment-311</guid>
		<description>Nice that looks a lot more efficient</description>
		<content:encoded><![CDATA[<p>Nice that looks a lot more efficient</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Volomike</title>
		<link>http://mattf.ca/php/simple-php-dates/comment-page-1/#comment-310</link>
		<dc:creator>Volomike</dc:creator>
		<pubDate>Thu, 31 Dec 2009 16:51:20 +0000</pubDate>
		<guid isPermaLink="false">http://mattf.ca/?p=101#comment-310</guid>
		<description>There&#039;s a faster, newer, more prescribed way to do this in PHP5 and it uses plain English, almost.

function doDate($nInterval) {
	$dDate = new DateTime();
	$dDate-&gt;modify(&quot;$nInterval&quot;);
	return $dDate-&gt;format(&#039;Y-m-d H:i:s&#039;);
}

echo doDate(&#039;+4 days&#039;);
echo &quot;\n&quot;;
echo doDate(&#039;-5 hours&#039;);
echo &quot;\n&quot;;
echo doDate(&#039;+2 weeks&#039;);
echo &quot;\n&quot;;
echo doDate(&#039;-5 weeks -2 days&#039;);

See how much more power it gives you? No messy 86400 stuff to add in, and it handles years, months, weeks, days, hours, minutes, and seconds, going backwards and forwards.

Note I could have also used your preferred formatting format for the .format() call of: ’l, F j, Y’.

The only trouble would be -- and you only see this when you turn on a Strict Standards error mode in your pages -- is that you should set the date and time first somewhere in your code to a particular timezone so that it doesn&#039;t just guess your server time. This is done easily, however, like so, and should be called before running doDate(). It only needs to be called once and then all subsequent doDate() calls will work fine.

// change to your timezone or use &quot;UTC&quot; for Universal Coordinated Time if that&#039;s your thing.
date_default_timezone_set(&#039;America/New_York&#039;);

(I do PHP for a living, working from home.)</description>
		<content:encoded><![CDATA[<p>There&#8217;s a faster, newer, more prescribed way to do this in PHP5 and it uses plain English, almost.</p>
<p>function doDate($nInterval) {<br />
	$dDate = new DateTime();<br />
	$dDate-&gt;modify(&#8220;$nInterval&#8221;);<br />
	return $dDate-&gt;format(&#8216;Y-m-d H:i:s&#8217;);<br />
}</p>
<p>echo doDate(&#8216;+4 days&#8217;);<br />
echo &#8220;\n&#8221;;<br />
echo doDate(&#8216;-5 hours&#8217;);<br />
echo &#8220;\n&#8221;;<br />
echo doDate(&#8216;+2 weeks&#8217;);<br />
echo &#8220;\n&#8221;;<br />
echo doDate(&#8216;-5 weeks -2 days&#8217;);</p>
<p>See how much more power it gives you? No messy 86400 stuff to add in, and it handles years, months, weeks, days, hours, minutes, and seconds, going backwards and forwards.</p>
<p>Note I could have also used your preferred formatting format for the .format() call of: ’l, F j, Y’.</p>
<p>The only trouble would be &#8212; and you only see this when you turn on a Strict Standards error mode in your pages &#8212; is that you should set the date and time first somewhere in your code to a particular timezone so that it doesn&#8217;t just guess your server time. This is done easily, however, like so, and should be called before running doDate(). It only needs to be called once and then all subsequent doDate() calls will work fine.</p>
<p>// change to your timezone or use &#8220;UTC&#8221; for Universal Coordinated Time if that&#8217;s your thing.<br />
date_default_timezone_set(&#8216;America/New_York&#8217;);</p>
<p>(I do PHP for a living, working from home.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Fraser</title>
		<link>http://mattf.ca/php/simple-php-dates/comment-page-1/#comment-309</link>
		<dc:creator>Matt Fraser</dc:creator>
		<pubDate>Thu, 24 Dec 2009 04:40:48 +0000</pubDate>
		<guid isPermaLink="false">http://mattf.ca/?p=101#comment-309</guid>
		<description>Your way is better.
I like it with strings just so its easier to glance at (I&#039;m not very bright right)
It&#039;s only used on LP&#039;s hence the echo, or else yeah it would return a var</description>
		<content:encoded><![CDATA[<p>Your way is better.<br />
I like it with strings just so its easier to glance at (I&#8217;m not very bright right)<br />
It&#8217;s only used on LP&#8217;s hence the echo, or else yeah it would return a var</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Jeffries</title>
		<link>http://mattf.ca/php/simple-php-dates/comment-page-1/#comment-308</link>
		<dc:creator>David Jeffries</dc:creator>
		<pubDate>Wed, 23 Dec 2009 04:09:43 +0000</pubDate>
		<guid isPermaLink="false">http://mattf.ca/?p=101#comment-308</guid>
		<description>Why make it so complex?

function doDate($days){
  echo date(&#039;l, F j, Y&#039;, time() + 86400 * $days);
}

Then you can pass it a positive (future) or negative (past) number.

I would also consider returning the date instead of echoing it out.  Perhaps a showDate() function should be created which echos the result of the doDate function.  This way, the doDate function could be reused if you ever needed to store the result in a variable, for example.</description>
		<content:encoded><![CDATA[<p>Why make it so complex?</p>
<p>function doDate($days){<br />
  echo date(&#8216;l, F j, Y&#8217;, time() + 86400 * $days);<br />
}</p>
<p>Then you can pass it a positive (future) or negative (past) number.</p>
<p>I would also consider returning the date instead of echoing it out.  Perhaps a showDate() function should be created which echos the result of the doDate function.  This way, the doDate function could be reused if you ever needed to store the result in a variable, for example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: itchy</title>
		<link>http://mattf.ca/php/simple-php-dates/comment-page-1/#comment-307</link>
		<dc:creator>itchy</dc:creator>
		<pubDate>Wed, 23 Dec 2009 00:03:50 +0000</pubDate>
		<guid isPermaLink="false">http://mattf.ca/?p=101#comment-307</guid>
		<description>nice matt, thats an elegant solution.</description>
		<content:encoded><![CDATA[<p>nice matt, thats an elegant solution.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
