I am trying to fix a timezone issue in a PHP 8.2 web application. Any date before 1940-02-25
has a one-day difference when comparing the production server (Debian 12) to my local development machine (Fedora 38). Both machines have PHP 8.2, the "Olson" Timezone Database version 2023.3
and PHP's timezone set to 'Europe/Amsterdam'
. But the production server behaves differently.
Below is a straight forward example of three dates: one before, one on and one after the 1940-02-25. I know there was a timezone-related event in Great Britain, but why should that affect the Amterdam timezone?
Curious: if I alter the timezone to 'Europe/London'
, both systems behave the same.
For comparison, I added a \DateTime->format()
for each date, too. They are correct on both systems.
$locale = 'nl_NL';
$tz = new \DateTimeZone('Europe/Amsterdam');
$dtfmt = new \IntlDateFormatter(
$locale, \IntlDateFormatter::NONE, \IntlDateFormatter::NONE,
$tz, \IntlDateFormatter::GREGORIAN, "E dd-MM-y"
);
$dt = new \DateTime('1940-02-24', $tz);
print '1940-02-24 => '. $dt->format(' d-m-Y').PHP_EOL;
print '1940-02-24 => '. $dtfmt->format($dt).PHP_EOL;
print PHP_EOL;
$dt = new \DateTime('1940-02-25', $tz);
print '1940-02-25 => '. $dt->format(' d-m-Y').PHP_EOL;
print '1940-02-25 => '. $dtfmt->format($dt).PHP_EOL;
print PHP_EOL;
$dt = new \DateTime('1940-02-26', $tz);
print '1940-02-26 => '. $dt->format(' d-m-Y').PHP_EOL;
print '1940-02-26 => '. $dtfmt->format($dt).PHP_EOL;
print PHP_EOL;
Expected output (and actual output on my local machine):
1940-02-24 => 24-02-1940
1940-02-24 => za 24-02-1940
1940-02-25 => 25-02-1940
1940-02-25 => zo 25-02-1940
1940-02-26 => 26-02-1940
1940-02-26 => ma 26-02-1940
Instead, I get this on the production server:
1940-02-24 => 24-02-1940
1940-02-24 => vr 23-02-1940
1940-02-25 => 25-02-1940
1940-02-25 => za 24-02-1940
1940-02-26 => 26-02-1940
1940-02-26 => ma 26-02-1940
How can I fix this discrepancy?
Thanks and kind regards,
Frans-Willem