3v4l.org

run code in 300+ PHP versions simultaneously
<?php $startDate = "2019-02-01"; $endDate = "2019-03-04"; date_default_timezone_set('UTC'); $zones = [ 'UTC', 'Etc/GMT+12', // west 'Etc/GMT-12', // east 'Cuba', // west 'Japan', // east 'Atlantic/Azores', // west 'Europe/Berlin', // east ]; foreach ($zones as $zoneName) { $zone = timezone_open($zoneName); $diff = date_create($startDate, $zone)->diff(date_create($endDate, $zone)); $test = date_create($startDate, $zone)->add($diff); printf('test: %s expected: %s diff->days: %s zone: %s %s', $test->format('Y-m-d\TH:i:s'), $endDate, $diff->days, $zone->getName(), "\r\n"); }
Output for 8.1.0 - 8.1.13, 8.1.15 - 8.1.28, 8.2.0, 8.2.2 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: UTC test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Etc/GMT+12 test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Etc/GMT-12 test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Cuba test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Japan test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Atlantic/Azores test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Europe/Berlin
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 test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: UTC test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Etc/GMT+12 test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Etc/GMT-12 test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Cuba test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Japan test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Atlantic/Azores test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Europe/Berlin
Output for 8.1.14, 8.2.1
test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: UTC Warning: timezone_open(): Unknown or bad timezone (Etc/GMT+12) in /in/LVQDJ on line 18 Fatal error: Uncaught TypeError: date_create(): Argument #2 ($timezone) must be of type ?DateTimeZone, bool given in /in/LVQDJ:19 Stack trace: #0 /in/LVQDJ(19): date_create('2019-02-01', false) #1 {main} thrown in /in/LVQDJ on line 19
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: UTC test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Etc/GMT+12 test: 2019-03-01T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Etc/GMT-12 test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Cuba test: 2019-03-01T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Japan test: 2019-03-04T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Atlantic/Azores test: 2019-03-01T00:00:00 expected: 2019-03-04 diff->days: 31 zone: Europe/Berlin

preferences:
151.01 ms | 403 KiB | 181 Q