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 7.2.0 - 7.2.31, 7.3.0 - 7.3.19, 7.4.0 - 7.4.7, 8.0.0alpha1 - alpha2
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