Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uicabpatweyler's avatar

Incorrect timezones with Carbon

I have these UTC specs :

UTC : 15:07:40

[https://www.timeanddate.com/time/difference/timezone/utc]

UTC/GMT - 6 Hours Ciudad de México : 09:07:40

[https://www.timeanddate.com/worldclock/mexico/mexico-city]

UTC/GMT - 5 Hours Quintana Roo, México : 10:07:40

[https://www.timeanddate.com/worldclock/mexico/cancun]

Based on the TZ of PHP according to this page:

Timezones PHP America: [https://www.php.net/manual/en/timezones.america.php]

Mexico => America/Mexico_City (-6 hours)

Cancun, Quintana Roo => America/Cancun (-5 hours)

When running with tinker

Carbon\Carbon::now('America/Mexico_City');

The following is displayed

Carbon\Carbon @1685027900 {#4327 date: 2023-05-25 10:18:20.629524 America/Mexico_City (-05:00), }

When running with tinker

Carbon\Carbon::now('America/Cancun');

The following is displayed

Carbon\Carbon @1685028007 {#4323 date: 2023-05-25 10:20:07.620210 America/Cancun (-05:00), }

According to the TimeZone for Mexico it is -6 hrs and Cancun is -5 hrs, but in both there is a difference of -5. There is no time difference even though the timezone on each Carbon run is different.

Laravel Framework 9.52.7 with Filament 2.x. In my 'app.php' configuration file the 'timezone' value is set to 'UTC'

Does anyone know why this happens? I appreciate the help to solve it

0 likes
6 replies
LaryAI's avatar
Level 58

The issue is that the timezone data used by PHP and Carbon is not always up-to-date with the latest timezone changes. In this case, the timezone data being used by PHP and Carbon is outdated and does not reflect the correct timezone offsets for Mexico City and Cancun.

To fix this issue, you can update the timezone data used by PHP and Carbon by installing the latest version of the timezone database. You can do this by running the following command in your terminal:

sudo pecl install timezonedb

Once the installation is complete, you will need to update your PHP configuration to use the new timezone data. You can do this by adding the following line to your php.ini file:

date.timezone = "America/Mexico_City"

Replace "America/Mexico_City" with the appropriate timezone for your location.

After updating your PHP configuration, you should be able to use Carbon to correctly calculate the timezone offsets for Mexico City and Cancun.

Snapey's avatar

Works fine for me in php 8.1.16

echo Carbon\Carbon::now('America/Mexico_City')->toIso8601String() . PHP_EOL;

echo Carbon\Carbon::now('America/Cancun')->toIso8601String();

2023-05-25T10:17:34-06:00
2023-05-25T11:17:34-05:00
uicabpatweyler's avatar

@Snapey I have run it again on another computer, which has Laragon installed

Carbon\Carbon::now('America/Cancun'); => Carbon\Carbon @1685042884 {#3498 date: 2023-05-25 14:28:04.120963 America/Cancun (-05:00), }

Carbon\Carbon::now('America/Merida'); => Carbon\Carbon @1685042889 {#3494 date: 2023-05-25 14:28:09.612775 America/Merida (-05:00), }

Carbon\Carbon::now('America/Mexico_City'); => Carbon\Carbon @1685042895 {#3500 date: 2023-05-25 14:28:15.084800 America/Mexico_City (-05:00), }

Php version 7.4.8

Is the problem related to my Windows 10 operating system?

uicabpatweyler's avatar

Being using Laragon for Windows 10, I updated the PHP version, from 8.1.3 to 8.1.19 and the problem has been solved.

Thank you very much @snapey for your help.

Please or to participate in this conversation.