1 時間間隔で 2 つの日付間の日付の配列を生成したいと考えています。
Inital date: 01-01-2013 00:00:00
Final date: 02-01-2013 00:00:00
元。結果の:
[01-01-2013 00:00:00, 01-01-2013 01:00:00, 01-01-2013 02:00:00, (...), 02-01-2013 00:00:00]
$start = new DateTime('2013-07-01 00:00:00', new DateTimeZone('UTC'));
$interval = new DateInterval('PT1H');
$end = new DateTime('2013-07-03 00:00:00', new DateTimeZone('UTC'));
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $date) {
$dateArray[] = $date->format('Y-m-d h:i:s');
}
var_dump($dateArray);
<?php
$start = '2013-01-01 00:00:00';
$end = '2013-01-02 00:00:00';
$dates = array();
$current = strtotime($start);
$offset = 0;
while ( $current < strtotime($end) ) {
$current = strtotime("$start +{$offset} hours");
$dates[] = date('d-m-Y H:i:s', $current);
$offset++;
}
print_r($dates);
これを試すことができます。
$start = mktime(0,0,0,1,1,2013);
$end = mktime(0,0,0,2,1,2013);
$inc = 60*60; // 1 hour
for ($x=$start; $x<=$end; $x+$inc ) {
$dates = date('d-m-Y H:i:s, $x);
}