<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP and Web Development Blog &#187; PHP5</title>
	<atom:link href="http://www.ebrueggeman.com/blog/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ebrueggeman.com/blog</link>
	<description>Tips and Tricks for Web Developers</description>
	<lastBuildDate>Tue, 03 Aug 2010 17:21:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using date objects in PHP 5</title>
		<link>http://www.ebrueggeman.com/blog/using-the-date-objects-in-php-5/</link>
		<comments>http://www.ebrueggeman.com/blog/using-the-date-objects-in-php-5/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 19:45:58 +0000</pubDate>
		<dc:creator>Elliott Brueggeman</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Date Objects]]></category>
		<category><![CDATA[PHP Functions]]></category>
		<category><![CDATA[PHP5]]></category>

		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/php/using-the-date-objects-in-php-5/</guid>
		<description><![CDATA[If you&#8217;re a seasoned PHP developer, and you initially learned PHP a few years ago, you may not be familiar with the new functions that PHP 5 (5.1+) provides for date manipulation. PHP has changed to an object based format, where you create an initial date object, modify if desired, and then output using a [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a seasoned PHP developer, and you initially learned PHP a few years ago, you may not be familiar with the new functions that PHP 5 (5.1+) provides for date manipulation. PHP has changed to an object based format, where you create an initial date object, modify if desired, and then output using a format you specify. This is a great step for PHP, which prior to these new functions, had many separate yet similar functions to do the same things.</p>
<p><strong>Example code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">date_default_timezone_set <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;America/New_York&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$date_object</span><span style="color: #339933;">=</span>date_create<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;9/18/2007&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$date_object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modify</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;+5 day&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">echo</span> <span style="color: #000088;">$date_object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This will print <strong>2007-09-23</strong>.</p>
<p>Note that we call the date_default_timezone_set() function before executing any date related code. This is a good idea when you are using a hosted site, where you do not have access to the php.ini file to set the master PHP timezone setting. <a href="http://us.php.net/manual/en/timezones.php">List of available timezones</a>.</p>
<p>The date_create() function takes any descriptive time string, identical to the older strtotime() function. See the manual page for <a href="http://us.php.net/manual/en/function.date-create.php">date_create</a>, <a href="http://us.php.net/manual/en/function.strtotime.php">strtotime </a>and <a href="http://www.gnu.org/software/tar/manual/html_node/tar_113.html">GNU Date Input Formats</a> for more information on how to specify a date related string for the date_create() function.</p>
<p>The date_format() function takes a format argument identical to the syntax that the date() function accepts. See the <a href="http://us.php.net/manual/en/function.date-format.php">date_format</a> and <a href="http://us.php.net/manual/en/function.date.php">date</a> PHP manual pages for more information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ebrueggeman.com/blog/using-the-date-objects-in-php-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
