Teach to use Y-m-d

Because xkcd.com/1179/
This commit is contained in:
Hannes Van De Vreken
2014-12-04 15:38:20 +01:00
parent e5143c4ff2
commit 26a86d27fd

View File

@@ -17,7 +17,7 @@ output.
$raw = '22. 11. 1968';
$start = \DateTime::createFromFormat('d. m. Y', $raw);
echo 'Start date: ' . $start->format('m/d/Y') . "\n";
echo 'Start date: ' . $start->format('Y-m-d') . "\n";
{% endhighlight %}
Calculating with DateTime is possible with the DateInterval class. DateTime has methods like `add()` and `sub()` that
@@ -52,7 +52,7 @@ $periodInterval = \DateInterval::createFromDateString('first thursday');
$periodIterator = new \DatePeriod($start, $periodInterval, $end, \DatePeriod::EXCLUDE_START_DATE);
foreach ($periodIterator as $date) {
// output each date in the period
echo $date->format('m/d/Y') . ' ';
echo $date->format('Y-m-d') . ' ';
}
{% endhighlight %}