mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-09 07:26:29 +02:00
Teach to use Y-m-d
Because xkcd.com/1179/
This commit is contained in:
@@ -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 %}
|
||||
|
||||
|
Reference in New Issue
Block a user