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); print $dates[4];
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" } 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" } 2016-01-03
Output for 5.6.14, 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" } 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" } 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" } 2015-11-18
Output for 7.0.2
array(4) { [1]=> string(10) "2016-02-22" [2]=> string(10) "2016-01-22" [3]=> string(10) "2015-12-22" [4]=> string(10) "2015-11-22" } 2015-11-22
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" } 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" } 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" } 2015-11-11
Output for 5.5.30, hhvm-3.10.0
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" } 2015-12-01
Output for 5.6.21
array(4) { [1]=> string(10) "2016-04-02" [2]=> string(10) "2016-03-02" [3]=> string(10) "2016-02-02" [4]=> string(10) "2016-01-02" } 2016-01-02
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" } 2015-12-09
Output for 5.6.19
array(4) { [1]=> string(10) "2016-02-07" [2]=> string(10) "2016-01-07" [3]=> string(10) "2015-12-07" [4]=> string(10) "2015-11-07" } 2015-11-07
Output for 5.6.18
array(4) { [1]=> string(10) "2016-02-15" [2]=> string(10) "2016-01-15" [3]=> string(10) "2015-12-15" [4]=> string(10) "2015-11-15" } 2015-11-15
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" } 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" } 2015-11-27
Output for 5.6.15
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" } 2015-11-29
Output for 5.6.13
array(4) { [1]=> string(10) "2016-03-15" [2]=> string(10) "2016-02-15" [3]=> string(10) "2016-01-15" [4]=> string(10) "2015-12-15" } 2015-12-15
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" } 2015-12-19
Output for 5.6.11
array(4) { [1]=> string(10) "2016-03-23" [2]=> string(10) "2016-02-23" [3]=> string(10) "2016-01-23" [4]=> string(10) "2015-12-23" } 2015-12-23
Output for 5.6.10
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" } 2015-12-25
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" } 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" } 2015-12-29
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" } 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" } 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" } 2015-11-08
Output for 5.5.32
array(4) { [1]=> string(10) "2016-02-17" [2]=> string(10) "2016-01-17" [3]=> string(10) "2015-12-17" [4]=> string(10) "2015-11-17" } 2015-11-17
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" } 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" } 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" } 2015-12-20
Output for 5.5.27
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" } 2015-12-22
Output for 5.5.26
array(4) { [1]=> string(10) "2016-03-26" [2]=> string(10) "2016-02-26" [3]=> string(10) "2016-01-26" [4]=> string(10) "2015-12-26" } 2015-12-26
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" } 2015-12-28
Output for 5.5.24
array(4) { [1]=> string(10) "2016-04-23" [2]=> string(10) "2016-03-23" [3]=> string(10) "2016-02-23" [4]=> string(10) "2016-01-23" } 2016-01-23
Output for 5.4.39 - 5.4.45
array(4) { [1]=> string(10) "2015-08-20" [2]=> string(10) "2015-07-20" [3]=> string(10) "2015-06-20" [4]=> string(10) "2015-05-20" } 2015-05-20
Output for 5.4.34 - 5.4.38
array(4) { [1]=> string(10) "2015-02-05" [2]=> string(10) "2015-01-05" [3]=> string(10) "2014-12-05" [4]=> string(10) "2014-11-05" } 2014-11-05
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" } 2014-05-07
Output for 5.2.0 - 5.2.17
Fatal error: Class 'DateInterval' not found in /in/Jq1Wb on line 4
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/Jq1Wb 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/Jq1Wb 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/Jq1Wb on line 3