Issue filtering by date equality
I'm running into an issue where I don't get any results for a value with matches in the db.
Example query using date string directly from db gives me two results:
If I send this value through new Date('xxx').toISOString() I get back:
2023-11-02T03:00:40.145Z
Same query with this value returns 0 results
I'm seeing the same behavior when trying to equality filter this value using drizzle IE:
where: eq(meetingEvents.startingAt, decodedCursor ? new Date(decodedCursor.startingAt) : afterDate),
Not sure if this is a known issue people have run into or if I'm just doing something wrong. Like maybe I need to use dates in string mode?8 Replies
Dates are always a problem. You can use
new Date(...).toISOString().replace("T", " ").replace("Z", "")
to get the format used in SQL
Actually, you need to account for your timezone too.
lolAren't they though 🥹
Thanks for the response. Looking forward to chewing on this and figuring out how to make sure date strings are correctly formatted throughout the system so my queries dont break sadface
I have date helpers in all my projects. It's a pain
@Angelelz after switching to string mode it looks like the driver or orm still delivers dates in iso8601 format - is that your experience as well? Off the top of my head the only time that would require format conversion on the client is for comparison in where?
What dialect are you using?
pg, mysql or sqlite
ah right postgres.js
Take a look at this issue, might be what you're facing
GitHub
[BUG]: Postgres truncate milliseconds from timestamp · Issue #877 ·...
What version of drizzle-orm are you using? 0.27.0 What version of drizzle-kit are you using? 0.19.3 Describe the Bug The postgres Timestamp column's mapFromDriverValue method was incorrectly tr...