Created
September 1, 2016 03:16
-
-
Save srinathweb/7a1a77d4585986b0854ae9f3f5047773 to your computer and use it in GitHub Desktop.
date interval
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 | |
| $start = new DateTime( '2013-10-01' ); | |
| $end = new DateTime( '2014-01-01 23:59:59' ); | |
| $interval = new DateInterval('P1D'); | |
| $period = new DatePeriod($start, $interval, $end); | |
| // only trigger every three weeks... | |
| $weekInterval = 3; | |
| // initialize fake week | |
| $fakeWeek = 0; | |
| $currentWeek = $start->format('W'); | |
| foreach ($period as $date) { | |
| if ($date->format('W') !== $currentWeek) { | |
| $currentWeek = $date->format('W'); | |
| $fakeWeek++; | |
| print ' WEEK ' . $currentWeek . '<br/>'; | |
| } | |
| if ($fakeWeek % $weekInterval !== 0) { | |
| continue; | |
| } | |
| $dayOfWeek = $date->format('l'); | |
| if ($dayOfWeek == 'Monday' || $dayOfWeek == 'Wednesday' || $dayOfWeek == 'Friday') { | |
| print $date->format('Y-m-d H:i:s') . ' ' . $dayOfWeek . '<br/>'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment