3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $date = new DateTime(); $interval = new DateInterval('P1M'); $dates = array(); for($i = 1; $i < 5; $i++){ $date->sub($interval); $dates[$i]=$date->format('Y-m-d'); } var_dump($dates);
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.26, 5.6.28, 7.0.14 - 7.1.0
array(4) { [1]=> string(10) "2014-02-10" [2]=> string(10) "2014-01-10" [3]=> string(10) "2013-12-10" [4]=> string(10) "2013-11-10" }
Output for 7.0.6
array(4) { [1]=> string(10) "2016-04-03" [2]=> string(10) "2016-03-03" [3]=> string(10) "2016-02-03" [4]=> string(10) "2016-01-03" }
Output for 5.5.30, 7.0.5
array(4) { [1]=> string(10) "2016-03-02" [2]=> string(10) "2016-02-02" [3]=> string(10) "2016-01-02" [4]=> string(10) "2015-12-02" }
Output for 7.0.4
array(4) { [1]=> string(10) "2016-02-10" [2]=> string(10) "2016-01-10" [3]=> string(10) "2015-12-10" [4]=> string(10) "2015-11-10" }
Output for 7.0.3
array(4) { [1]=> string(10) "2016-02-18" [2]=> string(10) "2016-01-18" [3]=> string(10) "2015-12-18" [4]=> string(10) "2015-11-18" }
Output for 7.0.2
array(4) { [1]=> string(10) "2016-02-21" [2]=> string(10) "2016-01-21" [3]=> string(10) "2015-12-21" [4]=> string(10) "2015-11-21" }
Output for 7.0.1
array(4) { [1]=> string(10) "2016-02-23" [2]=> string(10) "2016-01-23" [3]=> string(10) "2015-12-23" [4]=> string(10) "2015-11-23" }
Output for 7.0.0
array(4) { [1]=> string(10) "2016-02-26" [2]=> string(10) "2016-01-26" [3]=> string(10) "2015-12-26" [4]=> string(10) "2015-11-26" }
Output for hhvm-3.12.0
array(4) { [1]=> string(10) "2016-02-11" [2]=> string(10) "2016-01-11" [3]=> string(10) "2015-12-11" [4]=> string(10) "2015-11-11" }
Output for hhvm-3.10.0
array(4) { [1]=> string(10) "2016-02-29" [2]=> string(10) "2016-01-29" [3]=> string(10) "2015-12-29" [4]=> string(10) "2015-11-29" }
Output for 5.6.21
array(4) { [1]=> string(10) "2016-04-01" [2]=> string(10) "2016-03-01" [3]=> string(10) "2016-02-01" [4]=> string(10) "2016-01-01" }
Output for 5.6.20
array(4) { [1]=> string(10) "2016-03-09" [2]=> string(10) "2016-02-09" [3]=> string(10) "2016-01-09" [4]=> string(10) "2015-12-09" }
Output for 5.6.19
array(4) { [1]=> string(10) "2016-02-06" [2]=> string(10) "2016-01-06" [3]=> string(10) "2015-12-06" [4]=> string(10) "2015-11-06" }
Output for 5.6.18
array(4) { [1]=> string(10) "2016-02-14" [2]=> string(10) "2016-01-14" [3]=> string(10) "2015-12-14" [4]=> string(10) "2015-11-14" }
Output for 5.6.17
array(4) { [1]=> string(10) "2016-02-19" [2]=> string(10) "2016-01-19" [3]=> string(10) "2015-12-19" [4]=> string(10) "2015-11-19" }
Output for 5.6.16
array(4) { [1]=> string(10) "2016-02-27" [2]=> string(10) "2016-01-27" [3]=> string(10) "2015-12-27" [4]=> string(10) "2015-11-27" }
Output for 5.6.15
array(4) { [1]=> string(10) "2016-02-28" [2]=> string(10) "2016-01-28" [3]=> string(10) "2015-12-28" [4]=> string(10) "2015-11-28" }
Output for 5.6.14
array(4) { [1]=> string(10) "2016-03-01" [2]=> string(10) "2016-02-01" [3]=> string(10) "2016-01-01" [4]=> string(10) "2015-12-01" }
Output for 5.6.13
array(4) { [1]=> string(10) "2016-03-14" [2]=> string(10) "2016-02-14" [3]=> string(10) "2016-01-14" [4]=> string(10) "2015-12-14" }
Output for 5.6.12
array(4) { [1]=> string(10) "2016-03-19" [2]=> string(10) "2016-02-19" [3]=> string(10) "2016-01-19" [4]=> string(10) "2015-12-19" }
Output for 5.6.11
array(4) { [1]=> string(10) "2016-03-22" [2]=> string(10) "2016-02-22" [3]=> string(10) "2016-01-22" [4]=> string(10) "2015-12-22" }
Output for 5.6.10
array(4) { [1]=> string(10) "2016-03-24" [2]=> string(10) "2016-02-24" [3]=> string(10) "2016-01-24" [4]=> string(10) "2015-12-24" }
Output for 5.6.9
array(4) { [1]=> string(10) "2016-03-27" [2]=> string(10) "2016-02-27" [3]=> string(10) "2016-01-27" [4]=> string(10) "2015-12-27" }
Output for 5.6.8
array(4) { [1]=> string(10) "2016-03-29" [2]=> string(10) "2016-02-29" [3]=> string(10) "2016-01-29" [4]=> string(10) "2015-12-29" }
Output for 5.6.7
array(4) { [1]=> string(10) "2016-04-24" [2]=> string(10) "2016-03-24" [3]=> string(10) "2016-02-24" [4]=> string(10) "2016-01-24" }
Output for 5.5.35
array(4) { [1]=> string(10) "2016-04-22" [2]=> string(10) "2016-03-22" [3]=> string(10) "2016-02-22" [4]=> string(10) "2016-01-22" }
Output for 5.5.34
array(4) { [1]=> string(10) "2016-03-10" [2]=> string(10) "2016-02-10" [3]=> string(10) "2016-01-10" [4]=> string(10) "2015-12-10" }
Output for 5.5.33
array(4) { [1]=> string(10) "2016-02-08" [2]=> string(10) "2016-01-08" [3]=> string(10) "2015-12-08" [4]=> string(10) "2015-11-08" }
Output for 5.5.32
array(4) { [1]=> string(10) "2016-02-16" [2]=> string(10) "2016-01-16" [3]=> string(10) "2015-12-16" [4]=> string(10) "2015-11-16" }
Output for 5.5.31
array(4) { [1]=> string(10) "2016-02-20" [2]=> string(10) "2016-01-20" [3]=> string(10) "2015-12-20" [4]=> string(10) "2015-11-20" }
Output for 5.5.29
array(4) { [1]=> string(10) "2016-03-16" [2]=> string(10) "2016-02-16" [3]=> string(10) "2016-01-16" [4]=> string(10) "2015-12-16" }
Output for 5.5.28
array(4) { [1]=> string(10) "2016-03-20" [2]=> string(10) "2016-02-20" [3]=> string(10) "2016-01-20" [4]=> string(10) "2015-12-20" }
Output for 5.5.27
array(4) { [1]=> string(10) "2016-03-21" [2]=> string(10) "2016-02-21" [3]=> string(10) "2016-01-21" [4]=> string(10) "2015-12-21" }
Output for 5.5.26
array(4) { [1]=> string(10) "2016-03-25" [2]=> string(10) "2016-02-25" [3]=> string(10) "2016-01-25" [4]=> string(10) "2015-12-25" }
Output for 5.5.25
array(4) { [1]=> string(10) "2016-03-28" [2]=> string(10) "2016-02-28" [3]=> string(10) "2016-01-28" [4]=> string(10) "2015-12-28" }
Output for 5.5.24
array(4) { [1]=> string(10) "2016-03-30" [2]=> string(10) "2016-03-01" [3]=> string(10) "2016-02-01" [4]=> string(10) "2016-01-01" }
Output for 5.4.41 - 5.4.45
array(4) { [1]=> string(10) "2015-08-14" [2]=> string(10) "2015-07-14" [3]=> string(10) "2015-06-14" [4]=> string(10) "2015-05-14" }
Output for 5.4.39 - 5.4.40
array(4) { [1]=> string(10) "2015-04-10" [2]=> string(10) "2015-03-10" [3]=> string(10) "2015-02-10" [4]=> string(10) "2015-01-10" }
Output for 5.4.38
array(4) { [1]=> string(10) "2015-02-02" [2]=> string(10) "2015-01-02" [3]=> string(10) "2014-12-02" [4]=> string(10) "2014-11-02" }
Output for 5.4.34 - 5.4.37
array(4) { [1]=> string(10) "2015-01-08" [2]=> string(10) "2014-12-08" [3]=> string(10) "2014-11-08" [4]=> string(10) "2014-10-08" }
Output for 5.3.29, 5.4.27 - 5.4.32
array(4) { [1]=> string(10) "2014-08-07" [2]=> string(10) "2014-07-07" [3]=> string(10) "2014-06-07" [4]=> string(10) "2014-05-07" }
Output for 5.2.0 - 5.2.17
Fatal error: Class 'DateInterval' not found in /in/nbPSQ on line 4
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/nbPSQ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/nbPSQ on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/nbPSQ on line 3