From 26a86d27fd98c6d998125e2cd1be3c402f8c6c8a Mon Sep 17 00:00:00 2001 From: Hannes Van De Vreken Date: Thu, 4 Dec 2014 15:38:20 +0100 Subject: [PATCH] Teach to use Y-m-d Because xkcd.com/1179/ --- _posts/05-03-01-Date-and-Time.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/05-03-01-Date-and-Time.md b/_posts/05-03-01-Date-and-Time.md index f7f9a7b..8911c34 100644 --- a/_posts/05-03-01-Date-and-Time.md +++ b/_posts/05-03-01-Date-and-Time.md @@ -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 %}