3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('Europe/London'); $date3 = DateTime::createFromFormat('Y-m-d H:i:s', '2019-04-01 00:00:00'); // 2019-04-01 00:00:00.0 Europe/London (+01:00) $date4 = clone $date3; $date4->modify('+5 week'); // 2019-05-06 00:00:00.0 Europe/London (+01:00) echo "So the originally modified date with 5 weeks added is:"; print_r($date4); echo "\n\n"; // positive DIFF and addition echo "1. positive DIFF and addition\n"; echo "diff is: "; $positiveDifferenceDateInterval2 = $date3->diff($date4); // interval: + 1m 4d; days 35 print_r($positiveDifferenceDateInterval2->format('%R %mm %dd')); echo "; days: {$positiveDifferenceDateInterval2->days} \n"; $positiveAddedDate = clone $date3; $positiveAddedDate->add($positiveDifferenceDateInterval2); print_r($positiveAddedDate); echo "is it equal to \$date4? "; var_dump($date4->getTimestamp() === $positiveAddedDate->getTimestamp()); echo "\n"; // negative DIFF and addition echo "2. negative DIFF and addition\n"; echo "diff is: "; $negativeDifferenceDateInterval2 = $date4->diff($date3); // interval: - 1m 5d; days 35 print_r($negativeDifferenceDateInterval2->format('%R %mm %dd')); echo "; days {$negativeDifferenceDateInterval2->days}"; $negativeAddedDate = clone $date3; // so in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? how crazy is that?! $negativeAddedDate->sub($negativeDifferenceDateInterval2); print_r($negativeAddedDate); echo "is it equal to \$date4? "; var_dump($date4->getTimestamp() === $negativeAddedDate->getTimestamp()); echo "\n\n"; echo 'So in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? How crazy is that?!';
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
So the originally modified date with 5 weeks added is:DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) 1. positive DIFF and addition diff is: + 1m 5d; days: 35 DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) 2. negative DIFF and addition diff is: - 1m 5d; days 35DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) So in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? How crazy is that?!
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 So the originally modified date with 5 weeks added is:DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) 1. positive DIFF and addition diff is: + 1m 5d; days: 35 DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) 2. negative DIFF and addition diff is: - 1m 5d; days 35DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) So in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? How crazy is that?!
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
So the originally modified date with 5 weeks added is:DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) 1. positive DIFF and addition diff is: + 1m 4d; days: 35 DateTime Object ( [date] => 2019-05-05 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(false) 2. negative DIFF and addition diff is: - 1m 5d; days 35DateTime Object ( [date] => 2019-05-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) So in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? How crazy is that?!
Output for 5.3.3 - 5.3.29, 5.4.0 - 5.4.29, 5.5.0 - 5.5.13
So the originally modified date with 5 weeks added is:DateTime Object ( [date] => 2019-05-06 00:00:00 [timezone_type] => 3 [timezone] => Europe/London ) 1. positive DIFF and addition diff is: + 1m 4d; days: 35 DateTime Object ( [date] => 2019-05-05 00:00:00 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(false) 2. negative DIFF and addition diff is: - 1m 5d; days 35DateTime Object ( [date] => 2019-05-06 00:00:00 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) So in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? How crazy is that?!
Output for 5.3.0 - 5.3.2
So the originally modified date with 5 weeks added is:DateTime Object ( [date] => 2019-05-06 00:00:00 [timezone_type] => 3 [timezone] => Europe/London ) 1. positive DIFF and addition diff is: + 1m 5d; days: 35 DateTime Object ( [date] => 2019-05-06 00:00:00 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(true) 2. negative DIFF and addition diff is: - 1m 5d; days 35DateTime Object ( [date] => 2019-05-06 00:00:00 [timezone_type] => 3 [timezone] => Europe/London ) is it equal to $date4? bool(false) So in order to make it equal to $date4 I need to subtract a negative interval instead of adding a positive one? How crazy is that?!
Output for 5.2.10 - 5.2.17
Fatal error: Call to undefined method DateTime::createFromFormat() in /in/2MNE3 on line 5
Process exited with code 255.
Output for 5.2.0 - 5.2.9
Fatal error: Call to undefined method DateTime::createfromformat() in /in/2MNE3 on line 5
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/2MNE3 on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/2MNE3 on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/2MNE3 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_VARIABLE in /in/2MNE3 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/2MNE3 on line 6
Process exited with code 255.

preferences:
323.46 ms | 401 KiB | 466 Q