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') . "<br/>\n"; echo roundDateTime($minute)->format('Y-m-d H:i') . "<br/><br/>\n"; }
Output for 5.6.28, 7.0.14 - 7.1.0
2014-05-17 21:01<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:02<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:03<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:04<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:05<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:06<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:07<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:08<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:09<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:10<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:11<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:12<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:13<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:14<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:15<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:16<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:17<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:18<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:19<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:20<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:21<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:22<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:23<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:24<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:25<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:26<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:27<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:28<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:29<br/> 2014-05-17 21:00<br/><br/> 2014-05-17 21:30<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:31<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:32<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:33<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:34<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:35<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:36<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:37<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:38<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:39<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:40<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:41<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:42<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:43<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:44<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:45<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:46<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:47<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:48<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:49<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:50<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:51<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:52<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:53<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:54<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:55<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:56<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:57<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:58<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 21:59<br/> 2014-05-17 21:30<br/><br/> 2014-05-17 22:00<br/> 2014-05-17 22:00<br/><br/>
Output for 5.3.4 - 5.6.22, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.7
2014-05-17 23:01<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:02<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:03<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:04<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:05<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:06<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:07<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:08<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:09<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:10<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:11<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:12<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:13<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:14<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:15<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:16<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:17<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:18<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:19<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:20<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:21<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:22<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:23<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:24<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:25<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:26<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:27<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:28<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:29<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:30<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:31<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:32<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:33<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:34<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:35<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:36<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:37<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:38<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:39<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:40<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:41<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:42<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:43<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:44<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:45<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:46<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:47<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:48<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:49<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:50<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:51<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:52<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:53<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:54<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:55<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:56<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:57<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:58<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:59<br/> 2014-05-17 23:30<br/><br/> 2014-05-18 00:00<br/> 2014-05-18 00:00<br/><br/>
Output for 5.3.0 - 5.3.3
2014-05-17 23:01<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:02<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:03<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:04<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:05<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:06<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:07<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:08<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:09<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:10<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:11<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:12<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:13<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:14<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:15<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:16<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:17<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:18<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:19<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:20<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:21<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:22<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:23<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:24<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:25<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:26<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:27<br/> 2014-05-17 23:00<br/><br/> 2014-05-17 23:28<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:29<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:30<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:31<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:32<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:33<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:34<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:35<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:36<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:37<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:38<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:39<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:40<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:41<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:42<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:43<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:44<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:45<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:46<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:47<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:48<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:49<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:50<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:51<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:52<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:53<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:54<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:55<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:56<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:57<br/> 2014-05-17 23:30<br/><br/> 2014-05-17 23:58<br/> 2014-05-18 00:00<br/><br/> 2014-05-17 23:59<br/> 2014-05-18 00:00<br/><br/> 2014-05-18 00:00<br/> 2014-05-18 00:00<br/><br/>
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 18 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 19 Fatal error: Class 'DateInterval' not found in /in/TBFC2 on line 18
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 18 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 19 Fatal error: Class 'DateTime' not found in /in/TBFC2 on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 7 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/TBFC2 on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 7 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/TBFC2 on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/TBFC2 on line 7 Parse error: parse error, expecting `')'' in /in/TBFC2 on line 7
Process exited with code 255.