Querying a table with a timestamp returns an incorrect time with drizzle
Hi there, i'm using drizzle with a postgresql database. In one of my tables i have a timestamp. When a row gets created, the value is stored correctly in UTC time. However when I query the same row, the returned date object has an incorrect time (likely adjusted for my timezone) however it should be in UTC.
table:
timestamp in db attached
Date returned from query attached
Even though the timestamp is correctly being stored in UTC time in the database, when queried, the Date object is in "UTC" time (as indicated by the Z at the end of the string), so its been adjusted for no reason. How can I fix this?


15 Replies
timestamp() ignores the time zone in postgres. you're probably looking for timestampz()
ah, in drizzle you have to pass {withTimezone: true}
Even if the timestamp is being stored correctly in UTC in the db?
if they're stored correctly in UTC, it might just be related to how you print them haha. Since I'm pretty sure drizzle just returns a JavaScript Date object
But that's the weird thing, in the first screenshot i'm literally printing the exact output from the drizzle query


even with toISOString() it's the same thing
or as
toUTCString()
anyways, using {withTimezone: true}
works but it's just not very well documented
and/or is a bughttps://orm.drizzle.team/docs/column-types/pg
if you need more info :)
Drizzle ORM - PostgreSQL column types
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
specifically this section

I agree that it's weird tho, not sure why postgres wants to be different so badly
but it's doing the complete opposite here

its returning a
Date
object that has been adjusted
i'd have to do more debugging to see if it's an issue with the drizzle postgres driver or an issue with running it with bun or something else but just want to get back to my project 😂tbh i just do this
what is your system's timezone?
GMT+1 but it was storing correctly in UTC in the db
Anyways switching to timestamptz worked
nice
yeah deserialize issues i guess