3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $start_date = '2014-3-19'; $end_date = '2014-5-19'; $begin = new DateTime( $start_date ); $end = new DateTime(date("Y-m-d",strtotime("+1 day", strtotime($end_date)))); while($begin < $end) { $period[] = $begin->format('Y-m-d'); $begin->modify('+1 day'); } foreach($period as $val) { print_r("Value: " . $val . "\n"); print_r("isWeekend?: " . isWeekend($val) . "\n"); } function isWeekend($date) { return (date('N', strtotime($date)) >= 6); }
Output for 5.2.2 - 7.1.0
Value: 2014-03-19 isWeekend?: Value: 2014-03-20 isWeekend?: Value: 2014-03-21 isWeekend?: Value: 2014-03-22 isWeekend?: 1 Value: 2014-03-23 isWeekend?: 1 Value: 2014-03-24 isWeekend?: Value: 2014-03-25 isWeekend?: Value: 2014-03-26 isWeekend?: Value: 2014-03-27 isWeekend?: Value: 2014-03-28 isWeekend?: Value: 2014-03-29 isWeekend?: 1 Value: 2014-03-30 isWeekend?: 1 Value: 2014-03-31 isWeekend?: Value: 2014-04-01 isWeekend?: Value: 2014-04-02 isWeekend?: Value: 2014-04-03 isWeekend?: Value: 2014-04-04 isWeekend?: Value: 2014-04-05 isWeekend?: 1 Value: 2014-04-06 isWeekend?: 1 Value: 2014-04-07 isWeekend?: Value: 2014-04-08 isWeekend?: Value: 2014-04-09 isWeekend?: Value: 2014-04-10 isWeekend?: Value: 2014-04-11 isWeekend?: Value: 2014-04-12 isWeekend?: 1 Value: 2014-04-13 isWeekend?: 1 Value: 2014-04-14 isWeekend?: Value: 2014-04-15 isWeekend?: Value: 2014-04-16 isWeekend?: Value: 2014-04-17 isWeekend?: Value: 2014-04-18 isWeekend?: Value: 2014-04-19 isWeekend?: 1 Value: 2014-04-20 isWeekend?: 1 Value: 2014-04-21 isWeekend?: Value: 2014-04-22 isWeekend?: Value: 2014-04-23 isWeekend?: Value: 2014-04-24 isWeekend?: Value: 2014-04-25 isWeekend?: Value: 2014-04-26 isWeekend?: 1 Value: 2014-04-27 isWeekend?: 1 Value: 2014-04-28 isWeekend?: Value: 2014-04-29 isWeekend?: Value: 2014-04-30 isWeekend?: Value: 2014-05-01 isWeekend?: Value: 2014-05-02 isWeekend?: Value: 2014-05-03 isWeekend?: 1 Value: 2014-05-04 isWeekend?: 1 Value: 2014-05-05 isWeekend?: Value: 2014-05-06 isWeekend?: Value: 2014-05-07 isWeekend?: Value: 2014-05-08 isWeekend?: Value: 2014-05-09 isWeekend?: Value: 2014-05-10 isWeekend?: 1 Value: 2014-05-11 isWeekend?: 1 Value: 2014-05-12 isWeekend?: Value: 2014-05-13 isWeekend?: Value: 2014-05-14 isWeekend?: Value: 2014-05-15 isWeekend?: Value: 2014-05-16 isWeekend?: Value: 2014-05-17 isWeekend?: 1 Value: 2014-05-18 isWeekend?: 1 Value: 2014-05-19 isWeekend?:
Output for 5.2.0 - 5.2.1
Notice: Undefined variable: period in /in/jBJ28 on line 13 Warning: Invalid argument supplied for foreach() in /in/jBJ28 on line 13
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/jBJ28 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/jBJ28 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/jBJ28 on line 6