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); ?>
based on WUosD
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:45:10.004004 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31DateInterval Object ( [y] => 1 [m] => 2 [d] => 28 [h] => 1 [i] => 14 [s] => 50 [f] => -0.004004 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 454 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )
Output for 5.4.30 - 5.4.45, 5.5.14 - 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:45:10.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31DateInterval Object ( [y] => 1 [m] => 2 [d] => 28 [h] => 1 [i] => 14 [s] => 50 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 454 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )
Output for 5.3.27 - 5.3.29, 5.4.17 - 5.4.29, 5.5.0 - 5.5.13
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:45:10 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31DateInterval Object ( [y] => 1 [m] => 2 [d] => 28 [h] => 1 [i] => 14 [s] => 50 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 454 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )
Output for 5.3.0 - 5.3.26, 5.4.0 - 5.4.16
DateTime Object ( [date] => 2015-12-31 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2014-10-02 22:45:10 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 2015-12-31DateInterval Object ( [y] => 1 [m] => 2 [d] => 28 [h] => 1 [i] => 14 [s] => 50 [invert] => 1 [days] => 454 )
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/4oCKo on line 14
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/4oCKo 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/4oCKo 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/4oCKo on line 7