Python Datetime, MySQL & Django – Weird Bug

I ran into a strange bug in my application I am building:

When I saved a datetime of 2020-04-09 06:30:00 to the database it would convert to 2020-04-09 13:30:00, 7 hours different. Why?

First, I checked that MySQL, Python, and my Windows environment were all using Pacific time. Yes, they are. Everything shows the same time.

Next, I discovered that MySQL stores times in UTC as it is not timezone aware apparently.

Super annoying.

So I switched a option to:

USE_TZ = False

This turns off timezone aware dates, making MySQL easier to work with.

Solved my bug.

Published by

Joel Gross

Joel Gross is the CEO of Coalition Technologies.