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 = $date1->diff($date2); var_dump($diff); ?>
based on Kiflf
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:41:26.004070 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
Output for 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:41:26.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 07:53:10.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 20:51:03.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 07:05:40.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 07:36:55.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 13:22:18.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 18:25:11.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
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 20:06:12.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Uncaught Error: Call to a member function diff() on string in /in/JEH9D:14 Stack trace: #0 {main} thrown in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.6.28
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:41:26.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 03:12:07.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 19:39:39.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 15:10:36.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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-14 22:54:26.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 11:55:40.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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-27 21:51:13.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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-28 22:44:44.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 01:19:24.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 05:14:40.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 18:50:14.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 01:49:02.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 03:40:48.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 08:37:59.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 16:36:33.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.6.7
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2016-05-25 10:25:08.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on string in /in/JEH9D on line 14
Process exited with code 255.
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 06:53:32.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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-10 22:07:08.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 17:59:31.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 00:45:47.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 14:43:08.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 00:52:37.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 19:19:42.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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-20 21:55:40.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 00:20:57.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 06:06:24.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 12:09:29.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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 19:04:47.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:52:42.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:52:39.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:34.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:33.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:31.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:30.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:57:14.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.4.36 - 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:57:08.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.4.34 - 5.4.35
DateTime Object ( [date] => 2015-12-31 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2015-03-15 12:57:07.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
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:41:30.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.4.8 - 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:41:31 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.3.19 - 5.4.7
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:41:32 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.3.0 - 5.3.18
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:41:33 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.2.0 - 5.2.17
DateTime Object ( ) DateTime Object ( ) 2015-12-31 Fatal error: Call to a member function diff() on a non-object in /in/JEH9D on line 14
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/JEH9D 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/JEH9D 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/JEH9D on line 7