Skip to content

Instantly share code, notes, and snippets.

@zaru
Created July 5, 2012 05:19
Show Gist options
  • Save zaru/3051504 to your computer and use it in GitHub Desktop.
Save zaru/3051504 to your computer and use it in GitHub Desktop.
日付のイテレーション的なもの
<?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