dates in sqlite not being evaluated, causing "Invalid Date"

expiresAt: int("expires_at", { mode: "timestamp" })
.notNull()
.$defaultFn(() => new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)),
createdAt: int("created_at", { mode: "timestamp" })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),

expiresAt: int("expires_at", { mode: "timestamp" })
.notNull()
.$defaultFn(() => new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)),
createdAt: int("created_at", { mode: "timestamp" })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),

I have the following columns in my sqlite table, for some reason the expiresAt column works fine, when being read, its being evaluated as an actual date, and is saved in the database as an UNIX timestamp, however, the createdAt column is being saved as an actual ISO string date, but upon quering it shows INVALID DATE, why is it?
3 Replies
bun
bun4mo ago
Ok nice
Liam
Liam4mo ago
Hey OP, did you ever find a solution to this?
bun
bun4mo ago
Yeah the solution is to use sql’unixepoch’ (with template strings)