<?php
$date1 = date_create('2014-07-19 13:00');
$date2 = date_create('2014-07-20 13:00');
$newArr = array();
// if start date is to be included then use
$newArr[] = date_format($date1, 'Y-m-d H:i:s');
while($date1 < $date2) {
$date1 = date_add($date1,date_interval_create_from_date_string('1 hour'));
$newArr[] = date_format($date1, 'Y-m-d H:i:s');
}
echo "<pre>";
print_r($newArr);
echo "</pre>";
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- <pre>Array
(
[0] => 2014-07-19 13:00:00
[1] => 2014-07-19 14:00:00
[2] => 2014-07-19 15:00:00
[3] => 2014-07-19 16:00:00
[4] => 2014-07-19 17:00:00
[5] => 2014-07-19 18:00:00
[6] => 2014-07-19 19:00:00
[7] => 2014-07-19 20:00:00
[8] => 2014-07-19 21:00:00
[9] => 2014-07-19 22:00:00
[10] => 2014-07-19 23:00:00
[11] => 2014-07-20 00:00:00
[12] => 2014-07-20 01:00:00
[13] => 2014-07-20 02:00:00
[14] => 2014-07-20 03:00:00
[15] => 2014-07-20 04:00:00
[16] => 2014-07-20 05:00:00
[17] => 2014-07-20 06:00:00
[18] => 2014-07-20 07:00:00
[19] => 2014-07-20 08:00:00
[20] => 2014-07-20 09:00:00
[21] => 2014-07-20 10:00:00
[22] => 2014-07-20 11:00:00
[23] => 2014-07-20 12:00:00
[24] => 2014-07-20 13:00:00
)
</pre>
- Output for 5.2.2 - 5.2.17
- Fatal error: Call to undefined function date_add() in /in/nOQuK on line 10
Process exited with code 255. - Output for 5.2.0 - 5.2.1
- <pre>Array
(
[0] => 2014-07-19 13:00:00
)
</pre>
- Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
- Fatal error: Call to undefined function date_create() in /in/nOQuK on line 3
Process exited with code 255. - Output for 4.4.5 - 4.4.9
- Fatal error: Call to undefined function: date_create() in /in/nOQuK on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
- Fatal error: Call to undefined function: date_create() in /in/nOQuK on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1
- Fatal error: Call to undefined function: date_create() in /in/nOQuK on line 3
preferences:
293.78 ms | 401 KiB | 460 Q