DT
Drizzle Team•6mo ago
Manzi

MySQL2 and Datetime - UTC is wrong.

Hi! I'm having trouble with fetching and saving UTC Datetimes to the database. In the database everything works fine. UTC time is right if i for example say DEFAULT NOW(). However when i create a new Date() and try to save it to the database. Drizzle is doing it's own conversion before sending it up or something. My local machine is +2 UTC but the times drizzle sends to database is -2 utc. Do you know any fix for this? Is this a known error/bug?
10 Replies
rphlmr âš¡
rphlmr ⚡•6mo ago
👋 When you create a new Date(), it is in the local timezone of what creates this date (your local machine or in prod, your server) Do you see something like current datetime with a GMT+0200? ex in my machine : Fri Jul 19 2024 15:26:32 GMT+0200 (heure d’été d’Europe centrale) on the server it is expected to see 13:26:32
Manzi
ManziOP•6mo ago
Hi! I get this 🙂
No description
rphlmr âš¡
rphlmr ⚡•6mo ago
in your browser?
Manzi
ManziOP•6mo ago
It's nodejs
rphlmr âš¡
rphlmr ⚡•6mo ago
me too, but not in the browser 😅 I always set my TZ env to utc (same for my server) to prevent this kind of trouble. Here node console is giving you the result of .toISOString()
rphlmr âš¡
rphlmr ⚡•6mo ago
when it is passed to the constructor of Date it resolves in the local timezone
No description
rphlmr âš¡
rphlmr ⚡•6mo ago
I would say that what you see is expected but the representation of it depends on the TZ of the tool that displays it (a db dashboard, your front-end)
Manzi
ManziOP•6mo ago
Hmmm... I'm not sure how I would solve this then. Should I write process.env.TZ = 'UTC' at the top of my express js server file? I use Drizzle studio
rphlmr âš¡
rphlmr ⚡•6mo ago
Yeah I have the same behaviour with Postgres My default is new Date() and it outputs as UTC (-2h)
Manzi
ManziOP•6mo ago
This is really weird. I set the TZ env variable in node. However when I console log the date I get "2024-07-19T13:55:36.439Z" which is right time. But in drizzle studio it says "2024-07-19T11:55:36.000Z". And in the rest of my node application it's right and also in database via cli. But not in drizzle studio
Want results from more Discord servers?
Add your server