Created
October 21, 2016 09:59
-
-
Save MasterHans/41d4f197c385be4f3477d2d52245dd64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$raw = '22. 11. 1968'; | |
$start = DateTime::createFromFormat('d. m. Y', $raw); | |
echo 'Start date: ' . $start->format('Y-m-d') . "\n"; | |
<?php | |
// create a copy of $start and add one month and 6 days | |
$end = clone $start; | |
$end->add(new DateInterval('P1M6D')); | |
$diff = $end->diff($start); | |
echo 'Difference: ' . $diff->format('%m month, %d days (total: %a days)') . "\n"; | |
// Difference: 1 month, 6 days (total: 37 days) | |
<?php | |
if ($start < $end) { | |
echo "Start is before end!\n"; | |
} | |
<?php | |
// output all thursdays between $start and $end | |
$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('Y-m-d') . ' '; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment