3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * @param DateTime $dateTime The dateTime to be rounded * * @return DateTime The rounded DateTime */ function roundDateTime(\DateTime $dateTime) { $rounded = clone $dateTime; //Avoid side effects return $rounded->setTimestamp($rounded->getTimestamp() - $rounded->getTimestamp() % 1800); return $rounded; } // Test code below $start = new \DateTime(); $end = new \DateTime('+ 1 hour'); $interval = new \DateInterval('PT1M'); $period = new \DatePeriod($start, $interval, $end); foreach($period as $minute){ echo $minute->format('Y-m-d H:i') . "\n"; echo roundDateTime($minute)->format('Y-m-d H:i') . "\n\n"; }
Output for 5.6.28, 7.0.12 - 7.1.0
2014-05-17 21:02 2014-05-17 21:00 2014-05-17 21:03 2014-05-17 21:00 2014-05-17 21:04 2014-05-17 21:00 2014-05-17 21:05 2014-05-17 21:00 2014-05-17 21:06 2014-05-17 21:00 2014-05-17 21:07 2014-05-17 21:00 2014-05-17 21:08 2014-05-17 21:00 2014-05-17 21:09 2014-05-17 21:00 2014-05-17 21:10 2014-05-17 21:00 2014-05-17 21:11 2014-05-17 21:00 2014-05-17 21:12 2014-05-17 21:00 2014-05-17 21:13 2014-05-17 21:00 2014-05-17 21:14 2014-05-17 21:00 2014-05-17 21:15 2014-05-17 21:00 2014-05-17 21:16 2014-05-17 21:00 2014-05-17 21:17 2014-05-17 21:00 2014-05-17 21:18 2014-05-17 21:00 2014-05-17 21:19 2014-05-17 21:00 2014-05-17 21:20 2014-05-17 21:00 2014-05-17 21:21 2014-05-17 21:00 2014-05-17 21:22 2014-05-17 21:00 2014-05-17 21:23 2014-05-17 21:00 2014-05-17 21:24 2014-05-17 21:00 2014-05-17 21:25 2014-05-17 21:00 2014-05-17 21:26 2014-05-17 21:00 2014-05-17 21:27 2014-05-17 21:00 2014-05-17 21:28 2014-05-17 21:00 2014-05-17 21:29 2014-05-17 21:00 2014-05-17 21:30 2014-05-17 21:30 2014-05-17 21:31 2014-05-17 21:30 2014-05-17 21:32 2014-05-17 21:30 2014-05-17 21:33 2014-05-17 21:30 2014-05-17 21:34 2014-05-17 21:30 2014-05-17 21:35 2014-05-17 21:30 2014-05-17 21:36 2014-05-17 21:30 2014-05-17 21:37 2014-05-17 21:30 2014-05-17 21:38 2014-05-17 21:30 2014-05-17 21:39 2014-05-17 21:30 2014-05-17 21:40 2014-05-17 21:30 2014-05-17 21:41 2014-05-17 21:30 2014-05-17 21:42 2014-05-17 21:30 2014-05-17 21:43 2014-05-17 21:30 2014-05-17 21:44 2014-05-17 21:30 2014-05-17 21:45 2014-05-17 21:30 2014-05-17 21:46 2014-05-17 21:30 2014-05-17 21:47 2014-05-17 21:30 2014-05-17 21:48 2014-05-17 21:30 2014-05-17 21:49 2014-05-17 21:30 2014-05-17 21:50 2014-05-17 21:30 2014-05-17 21:51 2014-05-17 21:30 2014-05-17 21:52 2014-05-17 21:30 2014-05-17 21:53 2014-05-17 21:30 2014-05-17 21:54 2014-05-17 21:30 2014-05-17 21:55 2014-05-17 21:30 2014-05-17 21:56 2014-05-17 21:30 2014-05-17 21:57 2014-05-17 21:30 2014-05-17 21:58 2014-05-17 21:30 2014-05-17 21:59 2014-05-17 21:30 2014-05-17 22:00 2014-05-17 22:00 2014-05-17 22:01 2014-05-17 22:00
Output for 7.0.6
2016-05-03 17:23 2016-05-03 17:00 2016-05-03 17:24 2016-05-03 17:00 2016-05-03 17:25 2016-05-03 17:00 2016-05-03 17:26 2016-05-03 17:00 2016-05-03 17:27 2016-05-03 17:00 2016-05-03 17:28 2016-05-03 17:00 2016-05-03 17:29 2016-05-03 17:00 2016-05-03 17:30 2016-05-03 17:30 2016-05-03 17:31 2016-05-03 17:30 2016-05-03 17:32 2016-05-03 17:30 2016-05-03 17:33 2016-05-03 17:30 2016-05-03 17:34 2016-05-03 17:30 2016-05-03 17:35 2016-05-03 17:30 2016-05-03 17:36 2016-05-03 17:30 2016-05-03 17:37 2016-05-03 17:30 2016-05-03 17:38 2016-05-03 17:30 2016-05-03 17:39 2016-05-03 17:30 2016-05-03 17:40 2016-05-03 17:30 2016-05-03 17:41 2016-05-03 17:30 2016-05-03 17:42 2016-05-03 17:30 2016-05-03 17:43 2016-05-03 17:30 2016-05-03 17:44 2016-05-03 17:30 2016-05-03 17:45 2016-05-03 17:30 2016-05-03 17:46 2016-05-03 17:30 2016-05-03 17:47 2016-05-03 17:30 2016-05-03 17:48 2016-05-03 17:30 2016-05-03 17:49 2016-05-03 17:30 2016-05-03 17:50 2016-05-03 17:30 2016-05-03 17:51 2016-05-03 17:30 2016-05-03 17:52 2016-05-03 17:30 2016-05-03 17:53 2016-05-03 17:30 2016-05-03 17:54 2016-05-03 17:30 2016-05-03 17:55 2016-05-03 17:30 2016-05-03 17:56 2016-05-03 17:30 2016-05-03 17:57 2016-05-03 17:30 2016-05-03 17:58 2016-05-03 17:30 2016-05-03 17:59 2016-05-03 17:30 2016-05-03 18:00 2016-05-03 18:00 2016-05-03 18:01 2016-05-03 18:00 2016-05-03 18:02 2016-05-03 18:00 2016-05-03 18:03 2016-05-03 18:00 2016-05-03 18:04 2016-05-03 18:00 2016-05-03 18:05 2016-05-03 18:00 2016-05-03 18:06 2016-05-03 18:00 2016-05-03 18:07 2016-05-03 18:00 2016-05-03 18:08 2016-05-03 18:00 2016-05-03 18:09 2016-05-03 18:00 2016-05-03 18:10 2016-05-03 18:00 2016-05-03 18:11 2016-05-03 18:00 2016-05-03 18:12 2016-05-03 18:00 2016-05-03 18:13 2016-05-03 18:00 2016-05-03 18:14 2016-05-03 18:00 2016-05-03 18:15 2016-05-03 18:00 2016-05-03 18:16 2016-05-03 18:00 2016-05-03 18:17 2016-05-03 18:00 2016-05-03 18:18 2016-05-03 18:00 2016-05-03 18:19 2016-05-03 18:00 2016-05-03 18:20 2016-05-03 18:00 2016-05-03 18:21 2016-05-03 18:00 2016-05-03 18:22 2016-05-03 18:00
Output for 5.5.0 - 5.5.34, 5.6.0 - 5.6.20, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.5
2016-04-13 08:51 2016-04-13 08:30 2016-04-13 08:52 2016-04-13 08:30 2016-04-13 08:53 2016-04-13 08:30 2016-04-13 08:54 2016-04-13 08:30 2016-04-13 08:55 2016-04-13 08:30 2016-04-13 08:56 2016-04-13 08:30 2016-04-13 08:57 2016-04-13 08:30 2016-04-13 08:58 2016-04-13 08:30 2016-04-13 08:59 2016-04-13 08:30 2016-04-13 09:00 2016-04-13 09:00 2016-04-13 09:01 2016-04-13 09:00 2016-04-13 09:02 2016-04-13 09:00 2016-04-13 09:03 2016-04-13 09:00 2016-04-13 09:04 2016-04-13 09:00 2016-04-13 09:05 2016-04-13 09:00 2016-04-13 09:06 2016-04-13 09:00 2016-04-13 09:07 2016-04-13 09:00 2016-04-13 09:08 2016-04-13 09:00 2016-04-13 09:09 2016-04-13 09:00 2016-04-13 09:10 2016-04-13 09:00 2016-04-13 09:11 2016-04-13 09:00 2016-04-13 09:12 2016-04-13 09:00 2016-04-13 09:13 2016-04-13 09:00 2016-04-13 09:14 2016-04-13 09:00 2016-04-13 09:15 2016-04-13 09:00 2016-04-13 09:16 2016-04-13 09:00 2016-04-13 09:17 2016-04-13 09:00 2016-04-13 09:18 2016-04-13 09:00 2016-04-13 09:19 2016-04-13 09:00 2016-04-13 09:20 2016-04-13 09:00 2016-04-13 09:21 2016-04-13 09:00 2016-04-13 09:22 2016-04-13 09:00 2016-04-13 09:23 2016-04-13 09:00 2016-04-13 09:24 2016-04-13 09:00 2016-04-13 09:25 2016-04-13 09:00 2016-04-13 09:26 2016-04-13 09:00 2016-04-13 09:27 2016-04-13 09:00 2016-04-13 09:28 2016-04-13 09:00 2016-04-13 09:29 2016-04-13 09:00 2016-04-13 09:30 2016-04-13 09:30 2016-04-13 09:31 2016-04-13 09:30 2016-04-13 09:32 2016-04-13 09:30 2016-04-13 09:33 2016-04-13 09:30 2016-04-13 09:34 2016-04-13 09:30 2016-04-13 09:35 2016-04-13 09:30 2016-04-13 09:36 2016-04-13 09:30 2016-04-13 09:37 2016-04-13 09:30 2016-04-13 09:38 2016-04-13 09:30 2016-04-13 09:39 2016-04-13 09:30 2016-04-13 09:40 2016-04-13 09:30 2016-04-13 09:41 2016-04-13 09:30 2016-04-13 09:42 2016-04-13 09:30 2016-04-13 09:43 2016-04-13 09:30 2016-04-13 09:44 2016-04-13 09:30 2016-04-13 09:45 2016-04-13 09:30 2016-04-13 09:46 2016-04-13 09:30 2016-04-13 09:47 2016-04-13 09:30 2016-04-13 09:48 2016-04-13 09:30 2016-04-13 09:49 2016-04-13 09:30 2016-04-13 09:50 2016-04-13 09:30
Output for 5.6.21
2016-05-02 12:33 2016-05-02 12:30 2016-05-02 12:34 2016-05-02 12:30 2016-05-02 12:35 2016-05-02 12:30 2016-05-02 12:36 2016-05-02 12:30 2016-05-02 12:37 2016-05-02 12:30 2016-05-02 12:38 2016-05-02 12:30 2016-05-02 12:39 2016-05-02 12:30 2016-05-02 12:40 2016-05-02 12:30 2016-05-02 12:41 2016-05-02 12:30 2016-05-02 12:42 2016-05-02 12:30 2016-05-02 12:43 2016-05-02 12:30 2016-05-02 12:44 2016-05-02 12:30 2016-05-02 12:45 2016-05-02 12:30 2016-05-02 12:46 2016-05-02 12:30 2016-05-02 12:47 2016-05-02 12:30 2016-05-02 12:48 2016-05-02 12:30 2016-05-02 12:49 2016-05-02 12:30 2016-05-02 12:50 2016-05-02 12:30 2016-05-02 12:51 2016-05-02 12:30 2016-05-02 12:52 2016-05-02 12:30 2016-05-02 12:53 2016-05-02 12:30 2016-05-02 12:54 2016-05-02 12:30 2016-05-02 12:55 2016-05-02 12:30 2016-05-02 12:56 2016-05-02 12:30 2016-05-02 12:57 2016-05-02 12:30 2016-05-02 12:58 2016-05-02 12:30 2016-05-02 12:59 2016-05-02 12:30 2016-05-02 13:00 2016-05-02 13:00 2016-05-02 13:01 2016-05-02 13:00 2016-05-02 13:02 2016-05-02 13:00 2016-05-02 13:03 2016-05-02 13:00 2016-05-02 13:04 2016-05-02 13:00 2016-05-02 13:05 2016-05-02 13:00 2016-05-02 13:06 2016-05-02 13:00 2016-05-02 13:07 2016-05-02 13:00 2016-05-02 13:08 2016-05-02 13:00 2016-05-02 13:09 2016-05-02 13:00 2016-05-02 13:10 2016-05-02 13:00 2016-05-02 13:11 2016-05-02 13:00 2016-05-02 13:12 2016-05-02 13:00 2016-05-02 13:13 2016-05-02 13:00 2016-05-02 13:14 2016-05-02 13:00 2016-05-02 13:15 2016-05-02 13:00 2016-05-02 13:16 2016-05-02 13:00 2016-05-02 13:17 2016-05-02 13:00 2016-05-02 13:18 2016-05-02 13:00 2016-05-02 13:19 2016-05-02 13:00 2016-05-02 13:20 2016-05-02 13:00 2016-05-02 13:21 2016-05-02 13:00 2016-05-02 13:22 2016-05-02 13:00 2016-05-02 13:23 2016-05-02 13:00 2016-05-02 13:24 2016-05-02 13:00 2016-05-02 13:25 2016-05-02 13:00 2016-05-02 13:26 2016-05-02 13:00 2016-05-02 13:27 2016-05-02 13:00 2016-05-02 13:28 2016-05-02 13:00 2016-05-02 13:29 2016-05-02 13:00 2016-05-02 13:30 2016-05-02 13:30 2016-05-02 13:31 2016-05-02 13:30 2016-05-02 13:32 2016-05-02 13:30
Output for 5.5.35
2016-05-22 18:39 2016-05-22 18:30 2016-05-22 18:40 2016-05-22 18:30 2016-05-22 18:41 2016-05-22 18:30 2016-05-22 18:42 2016-05-22 18:30 2016-05-22 18:43 2016-05-22 18:30 2016-05-22 18:44 2016-05-22 18:30 2016-05-22 18:45 2016-05-22 18:30 2016-05-22 18:46 2016-05-22 18:30 2016-05-22 18:47 2016-05-22 18:30 2016-05-22 18:48 2016-05-22 18:30 2016-05-22 18:49 2016-05-22 18:30 2016-05-22 18:50 2016-05-22 18:30 2016-05-22 18:51 2016-05-22 18:30 2016-05-22 18:52 2016-05-22 18:30 2016-05-22 18:53 2016-05-22 18:30 2016-05-22 18:54 2016-05-22 18:30 2016-05-22 18:55 2016-05-22 18:30 2016-05-22 18:56 2016-05-22 18:30 2016-05-22 18:57 2016-05-22 18:30 2016-05-22 18:58 2016-05-22 18:30 2016-05-22 18:59 2016-05-22 18:30 2016-05-22 19:00 2016-05-22 19:00 2016-05-22 19:01 2016-05-22 19:00 2016-05-22 19:02 2016-05-22 19:00 2016-05-22 19:03 2016-05-22 19:00 2016-05-22 19:04 2016-05-22 19:00 2016-05-22 19:05 2016-05-22 19:00 2016-05-22 19:06 2016-05-22 19:00 2016-05-22 19:07 2016-05-22 19:00 2016-05-22 19:08 2016-05-22 19:00 2016-05-22 19:09 2016-05-22 19:00 2016-05-22 19:10 2016-05-22 19:00 2016-05-22 19:11 2016-05-22 19:00 2016-05-22 19:12 2016-05-22 19:00 2016-05-22 19:13 2016-05-22 19:00 2016-05-22 19:14 2016-05-22 19:00 2016-05-22 19:15 2016-05-22 19:00 2016-05-22 19:16 2016-05-22 19:00 2016-05-22 19:17 2016-05-22 19:00 2016-05-22 19:18 2016-05-22 19:00 2016-05-22 19:19 2016-05-22 19:00 2016-05-22 19:20 2016-05-22 19:00 2016-05-22 19:21 2016-05-22 19:00 2016-05-22 19:22 2016-05-22 19:00 2016-05-22 19:23 2016-05-22 19:00 2016-05-22 19:24 2016-05-22 19:00 2016-05-22 19:25 2016-05-22 19:00 2016-05-22 19:26 2016-05-22 19:00 2016-05-22 19:27 2016-05-22 19:00 2016-05-22 19:28 2016-05-22 19:00 2016-05-22 19:29 2016-05-22 19:00 2016-05-22 19:30 2016-05-22 19:30 2016-05-22 19:31 2016-05-22 19:30 2016-05-22 19:32 2016-05-22 19:30 2016-05-22 19:33 2016-05-22 19:30 2016-05-22 19:34 2016-05-22 19:30 2016-05-22 19:35 2016-05-22 19:30 2016-05-22 19:36 2016-05-22 19:30 2016-05-22 19:37 2016-05-22 19:30 2016-05-22 19:38 2016-05-22 19:30
Output for 5.4.0 - 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /in/Xvs2v:16 Stack trace: #0 /in/Xvs2v(16): DateTime->__construct() #1 {main} thrown in /in/Xvs2v on line 16
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead' in /in/Xvs2v:16 Stack trace: #0 /in/Xvs2v(16): DateTime->__construct() #1 {main} thrown in /in/Xvs2v on line 16
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Xvs2v on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Xvs2v on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Xvs2v on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Xvs2v on line 18 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Xvs2v on line 19 Fatal error: Class 'DateInterval' not found in /in/Xvs2v on line 18
Process exited with code 255.
Output for 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>7</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>16</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>17</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>18</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>19</b><br /> <br /> <b>Fatal error</b>: Class 'DateInterval' not found in <b>/in/Xvs2v</b> on line <b>18</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.1.6
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>7</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>16</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>17</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>18</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>19</b><br /> <br /> <b>Fatal error</b>: Class 'DateTime' not found in <b>/in/Xvs2v</b> on line <b>16</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>7</b><br /> <br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting ')' in <b>/in/Xvs2v</b> on line <b>7</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>7</b><br /> <br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting ')' in <b>/in/Xvs2v</b> on line <b>7</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/Xvs2v</b> on line <b>7</b><br /> <br /> <b>Parse error</b>: parse error, expecting `')'' in <b>/in/Xvs2v</b> on line <b>7</b><br />
Process exited with code 255.