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'); $date2 = $start_time->format('Y-m-d'); $diff = $start_time->diff($end_time); print_r($diff->format('Y-m-d')); ?>
based on p7r4H
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:48:45.004024 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:48:45.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:29.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:37.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:04.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:38.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:07.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:21.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:50.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:23.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:40.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:47.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:27.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:06.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:23.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:37.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:48.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:32.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:29.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:27.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:55.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:28.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:52.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:12.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:18:03.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:49.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:36.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:43.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:53:03.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:50.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:12:16.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:45.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:42.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:39.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:38.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:36.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:35.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:51:34.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:56:05.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:55:57.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:55:56.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-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:48:49.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-m-d
Output for 5.4.19 - 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:48:49 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-m-d
Output for 5.3.29 - 5.4.18
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:48:50 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-m-d
Output for 5.3.8 - 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:48:51 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-m-d
Output for 5.3.0 - 5.3.7
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:48:52 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) Y-m-d
Output for 5.2.0 - 5.2.17
DateTime Object ( ) DateTime Object ( ) Fatal error: Call to undefined method DateTime::diff() in /in/1Tcio on line 15
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/1Tcio 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/1Tcio 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/1Tcio on line 7