0

Why are these two things showing different times?

select CONVERT_TZ('2023-05-03 00:00:00', '-06:00', @@global.time_zone);
Outputs:

2023-05-03 06:00:00


$date = new \DateTime('2023-05-03 00:00:00', new \DateTimeZone('America/Chicago'));
$date->setTimezone(new \DateTimeZone('UTC'));
echo $date->format('Y-m-d H:i:s');
Outputs:

2023-05-03 05:00:00

-06:00 is America/Chicago. So why there is a difference of 1 hour? Can any one guide me to the correct way please?

Yunus Aslam
  • 2,447
  • 4
  • 25
  • 39
  • Using [GMT, like this might be of some use to you](https://stackoverflow.com/a/2934271/1389394) – bonCodigo May 04 '23 at 08:13
  • 1
    Assuming that `@@global.time_zone` equal `UTC` (please verify just in case), Chicago current time appears to be -0500 ([source](https://www.worldtimeserver.com/current_time_in_US-IL.aspx?city=Chicago)). – Álvaro González May 04 '23 at 08:33

1 Answers1

1

"-06:00 is America/Chicago" - no, that depends on time of year. When you pass -06:00 you mean exactly that offset, with no daylight saving rules. Pass "America/Chicago" instead. (If it then returns null, you need to load the MySQL timezone tables - see https://dev.mysql.com/doc/refman/8.0/en/mysql-tzinfo-to-sql.html )

ysth
  • 96,171
  • 6
  • 121
  • 214
  • Thank you for your help. I did the same thing, instead of passing "-06:00", I passed America/Chicago and that helped me fix my problem. – Yunus Aslam May 09 '23 at 09:27