3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "blah 2015 yar"; $pos = strpos($string, "20"); $year = substr($string, $pos, 4); $end_year = "12/31/" . $year; $end_time = new DateTime($end_year); print_r($end_time); $start_time = new DateTime(); print_r($start_time); $date1 = $end_time->format('Y-m-d'); echo $date1; $date2 = $start_time->format('Y-m-d'); $diff = $end_time->diff($start_time); print_r($diff->format('Y-m-d')); ?>
based on u1gOb
Output for 7.1.0
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:35.004036 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.28, 7.0.14
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.6
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-05-03 10:16:12.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.5
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-02 23:03:32.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.4
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-10 09:39:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.3
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-18 10:18:33.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.2
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-22 16:17:02.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.1
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-23 20:53:16.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 7.0.0
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-26 22:25:45.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for hhvm-3.12.0
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-12 12:53:21.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for hhvm-3.10.0
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-30 11:58:42.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.21
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-05-02 05:36:08.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.20
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-09 22:02:10.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.19
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-07 17:46:42.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.18
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-15 01:51:45.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.17
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-19 14:32:30.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.16
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-28 00:13:22.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.15
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-29 01:18:02.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.14
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-02 03:37:19.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.13
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-15 07:31:32.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.12
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-19 21:19:17.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.11
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-23 04:21:33.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.10
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-25 06:06:16.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.9
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-27 11:05:13.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.6.8
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-29 19:13:10.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.35
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-05-22 09:23:39.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.34
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-11 00:22:23.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.33
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-08 20:43:48.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.32
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-17 03:26:07.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.31
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-03-20 17:17:59.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.30
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-01 03:14:44.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.29
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-16 21:38:31.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.28
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-21 00:34:25.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.27
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-22 02:52:47.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.26
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-26 08:32:33.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.25
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-04-28 14:51:03.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.5.24
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-05-23 22:11:48.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.45
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:53:05.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.44
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:53:02.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.43
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:52:59.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.42
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:52:58.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.41
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:52:56.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.40
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:52:55.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.39
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-09-20 09:52:54.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.38
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-03-15 12:58:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.35 - 5.4.37
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-03-15 12:58:28.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.34
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-03-15 12:58:27.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.30 - 5.4.32
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:39.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.4.20 - 5.4.29
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:39 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.3.29 - 5.4.19
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:40 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.3.7 - 5.3.28
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:41 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.3.0 - 5.3.6
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:47:42 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31Y-m-d
Output for 5.2.0 - 5.2.17
DateTime Object ( ) DateTime Object ( ) 2015-12-31 Fatal error: Call to undefined method DateTime::diff() in /in/p7r4H on line 16
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/p7r4H on line 7
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/p7r4H on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/p7r4H on line 7