3v4l.org

run code in 300+ PHP versions simultaneously
<?php $offset = 5; $offsetStr = "PT".$offset."H"; $date = new DateTime("18-July-2008 16:30:30"); $date->sub($date, new DateInterval($offsetStr)); echo $date->format("d-m-Y H:i:s").' : 2 Hours'; echo $date->format("d-m-Y H:i:s").'<br />'; echo '<br />'.$date->format("d-m-Y").' : 5 Days'; date_sub($date, new DateInterval("P5Y5M5D")); echo '<br />'.$date->format("d-m-Y").' : 5 Days, 5 Months, 5 Years'; date_sub($date, new DateInterval("P5YT5H")); echo '<br />'.$date->format("d-m-Y H:i:s").' : 5 Years, 5 Hours'; ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: DateTime::sub() expects exactly 1 argument, 2 given in /in/hk1rE:7 Stack trace: #0 /in/hk1rE(7): DateTime->sub(Object(DateTime), Object(DateInterval)) #1 {main} thrown in /in/hk1rE on line 7
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: DateTime::sub() expects exactly 1 parameter, 2 given in /in/hk1rE on line 7 18-07-2008 16:30:30 : 2 Hours18-07-2008 16:30:30<br /><br />18-07-2008 : 5 Days<br />13-02-2003 : 5 Days, 5 Months, 5 Years<br />13-02-1998 11:30:30 : 5 Years, 5 Hours
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::sub() in /in/hk1rE on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/hk1rE on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/hk1rE 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/hk1rE on line 6

preferences:
267.86 ms | 401 KiB | 375 Q