<?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>devexp &#187; date</title>
	<atom:link href="http://www.devexp.eu/tag/date/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexp.eu</link>
	<description>DEVelopment EXPerience, shared with the world!</description>
	<lastBuildDate>Fri, 28 Oct 2011 12:07:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A few helpful PHP date methods</title>
		<link>http://www.devexp.eu/2009/04/14/a-few-helpfull-php-date-methods/</link>
		<comments>http://www.devexp.eu/2009/04/14/a-few-helpfull-php-date-methods/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 11:08:28 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=639</guid>
		<description><![CDATA[For a lot of people dates in PHP are an issue, and the PHP functions aren&#8217;t sufficient enough to do all converts you need. Therefore you find a few easy PHP date conversion methods. Feel free to add your own &#8230; <a href="http://www.devexp.eu/2009/04/14/a-few-helpfull-php-date-methods/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>For a lot of people dates in PHP are an issue, and the PHP functions aren&#8217;t sufficient enough to do all converts you need.<br />
Therefore you find a few easy PHP date conversion methods. Feel free to add your own methods or requests in the comments as we know that these methods don&#8217;t cover everything. You can see it for yourself when you read the rest of this entry:</p>
<ul>
<li>get start and end date for the next two months in an array</li>
<li>get the datetime for a specific user culture in Symfony</li>
<li>get all days between a given start and end date and return it in an array</li>
<li>get the difference between two dates</li>
</ul>
<p><span id="more-639"></span></p>
<ol>
<li><strong>get start and end date for the next two months in an array </strong><span style="text-decoration: underline;"><br />
input</span>: nothing<br />
<span style="text-decoration: underline;">output</span>:<br />
array[0] = 1239706452<br />
array[1] = 1244976852<br />
<span style="color: #339966;">*updated -&gt; thx naholyr</span>
<pre class="brush: php; title: ; notranslate">
/**
 * get the next two months starting from today.
 *
 * @return array
 */
 public function getNextTwoMonths(){
 return array(time(), strtotime(’+2 month’));
 }
</pre>
</li>
<li><strong>get the datetime for a specific user culture in Symfony</strong><span style="text-decoration: underline;"><br />
input</span>: 16/09/08 <span style="text-decoration: underline;"><br />
output</span>: 2008-09-16 23:35:55
<pre class="brush: php; title: ; notranslate">
 /**
 * Parses a date String from a specific culture to a Date.
 *
 * input example: 16/09/08
 *
 * returns: DateTime (Date)
 * @param String $period
 * @return Array of DateTime objects
 */
 public function parseDate($period) {

 $userCulture =  sfContext::getInstance()-&gt;getUser()-&gt;getCulture();

 $timestamp = sfContext::getInstance()-&gt;getI18N()-&gt;getTimestampForCulture($period, $userCulture);

 $period = new DateTime(date('Y-m-d H:i:s', $timestamp));

 return $period;
 }
</pre>
</li>
<li><strong>get all days between a given start and end date and return it in an array.</strong><span style="text-decoration: underline;"><br />
input</span>: 2 DateTime dates<span style="text-decoration: underline;"><br />
output</span>: array of days<br />
day[0] = 2008-12-10<br />
day[1] = 2008-12-11
<pre class="brush: php; title: ; notranslate">
/**
 * With a given start and end date it will creates all the dates in between and return
 * it in an array.
 *
 * @param DateTime $startDate
 * @param DateTime $endDate
 * @return Array
 */
 public function getDaysByPeriod(DateTime $startDate, DateTime $endDate) {

 $startDt = clone $startDate;

 $days = array();

 while ( $startDt-&gt;format('U') &lt;= $endDt-&gt;format('U') ) {
 $days[] = $startDt-&gt;format('Y-m-d');
 $startDt-&gt;modify(&quot;+1 days&quot;);
 }

 return $days;
 }
</pre>
</li>
<li><strong>get the difference between two dates</strong><span style="text-decoration: underline;"><br />
input</span>: <span style="text-decoration: underline;"><br />
</span>2009-04-14 10:08:35<br />
2009-04-15 10:10:35<br />
<span style="text-decoration: underline;"> output</span>: unix timestamp of the difference<br />
<span style="color: #339966;">* updated -&gt; thx Toni and David</span>
<pre class="brush: php; title: ; notranslate">
/**
 * get the difference between two dates
 *
 * @param date $firstTime
 * @param date $lastTime
 * @return integer
 */
public function timeDiff($firstTime,$lastTime)
{
 return strtotime($lastTime) - strtotime($firstTime);
}
</pre>
</li>
</ol>
<div class="shr-publisher-639"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/14/a-few-helpfull-php-date-methods/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>conversion of dates</title>
		<link>http://www.devexp.eu/2009/03/06/conversion-of-dates/</link>
		<comments>http://www.devexp.eu/2009/03/06/conversion-of-dates/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 08:06:13 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[day]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[week]]></category>
		<category><![CDATA[year]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=391</guid>
		<description><![CDATA[I struggled with a bit of code last week, but found a nice solution. The goal was to convert 3 parameters into a date: 1. The day of the week (0 -&#62; 6, 0 = Monday, 1 = Tuesday, 2 &#8230; <a href="http://www.devexp.eu/2009/03/06/conversion-of-dates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I struggled with a bit of code last week, but found a nice solution.</p>
<p>The goal was to convert 3 parameters into a date:</p>
<p>1. The day of the week (0 -&gt; 6, 0 = Monday, 1 = Tuesday, 2 = Wednesday, etc.)<br />
2. The week number (0 – 53, <a title="windows bug in week numbers" href="http://www.devexp.eu/?p=385" target="_self">see our previous post for more info</a>)<br />
3. And the year (2009)</p>
<p>Well in this function we got to that result.</p>
<pre class="brush: php; title: ; notranslate">
/**
* create datetime from dow, week number and year
* @param integer $dow (MUST BE 0 -&gt; 6)
* @param integer $weekNumber
* @param integer $year
* @return datetime
*/
public function getDateTimeByDowWeekYear ($dow, $weekNumber, $year) {
// get the first day of the current year, according iso standards
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset &lt; 5) ? 1-$offset : 8-$offset;
//get the first Monday of the year
$monday = mktime(0,0,0,1,1+$offset,$year);
//add the number of weeks
$mondayTime = strtotime('+' . ($weekNumber - 1) . ' weeks', $monday);
// add the number of weekdays
$dayTime = strtotime('+' . $dow . ' days', $mondayTime);
//create a date
return date('Y-m-d H:i:s',$dayTime);
}
</pre>
<p>It seemed to be a lot easier then I thought.<br />
Et voila, have fun.</p>
<div class="shr-publisher-391"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/03/06/conversion-of-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

