Created
July 5, 2012 05:19
-
-
Save zaru/3051504 to your computer and use it in GitHub Desktop.
日付のイテレーション的なもの
This file contains 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 | |
//PHP5.3以前 | |
$begin = strtotime('2012-01-05'); | |
$end = strtotime('2012-02-15') + 1; | |
while($begin < $end){ | |
echo date('Y-m-d', $begin) . "\n"; | |
$begin = strtotime("+1 day", $begin); | |
} | |
//PHP5.3以上 | |
$period = new DatePeriod( | |
new DateTime('2011-01-05'), | |
new DateInterval('P1D'), | |
new DateTime('2011-02-15 +1 second') | |
); | |
foreach ($period as $day) { | |
echo $day->format('Y-m-d') . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment