skip to Main Content

I have a problem with php in converting dates between timezones.
In particular using the DateTime and DateTimeZone functions I get that the current offset of America/Mexico_City is -5 hours w.r.t UTC (-18000 seconds)

$dateTimeZone = new DateTimeZone('America/Mexico_City');
$date = new DateTime('NOW');
$offset = $dateTimeZone->getOffset( $date ); // -> here $offset = -18000

I read that Mexico cancelled the DST last year: https://www.timeanddate.com/news/time/mexico-abolishes-dst-2022.html

And now if you check the current time they say that the current offset is -6 hours w.r.t UTC:
https://www.zeitverschiebung.net/en/city/3530597

Anyone experiencing this problem?
I think I should open a bug to PHP but I’d like to double check if I am doing something wrong and if anyone else is experiencing this problem.

Thanks,

2

Answers


  1. Chosen as BEST ANSWER

    We found out that our PHP installation was using a timezone library outdated, we checked our php ini file in the "date" section.
    Our system department updated the library and now the problem is gone.
    Thanks a lot for your help S.O. community :)


  2. You are probably using a very old version of PHP, which is why your libraries "don’t know" that Mexico has dropped DST.

    Try upgrading your PHP version to something that is actively supported like 8.1 or 8.2.

    I checked it locally and in PHP 8.1.13 I get offset -21600, in PHP 8.1.12 -18000.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search