Querying a table with a timestamp returns an incorrect time

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:
export const sessions = pgTable("session", {
id: text().notNull().primaryKey(),
secretHash: text().notNull(),
lastVerifiedAt: timestamp().notNull(),
createdAt: timestamp().defaultNow().notNull(),

userId: text().notNull().references(() => users.id)
})
export const sessions = pgTable("session", {
id: text().notNull().primaryKey(),
secretHash: text().notNull(),
lastVerifiedAt: timestamp().notNull(),
createdAt: timestamp().defaultNow().notNull(),

userId: text().notNull().references(() => users.id)
})
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?
No description
No description
1 Reply
aleclarson
aleclarson2mo ago
try using timestamp({ withTimezone: true })

Did you find this page helpful?