P
Prisma•4d ago
max

Is there a way to differently parse DateTime and db.Date when reading from Postgres

Both DateTime and db.Date are being parsed into a full Date in js. This causes unwanted behavior since the Day will shift for negative Timezones and hand-picking the affected fields for differenting handling is not a viable solution for me. I'd like a generic way to apply a different parsing strategy for different Database types
4 Replies
Prisma AI Help
Prisma AI Help•4d ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul•4d ago
Hey 👋 If I understand correctly, is your issue similar to what is described here? https://github.com/prisma/prisma/issues/7490
GitHub
Allow passing YYYY-MM-DD in native database date types to avoid t...
Bug description When I insert a date value, it gets stored in the database date attribute with a day off by one. How to reproduce I create a date object via new Date(1960, 8, 24) and I insert it on...
Nurul
Nurul•4d ago
One workaround (not so great) could be to store Date in a String format
max
maxOP•4d ago
somewhat similar but i was more looking for something like this which doesn't work for some reason:
import pg from 'pg';

pg.types.setTypeParser(1082, (val) => {
return `DATEONLY-${val}`;
});
import pg from 'pg';

pg.types.setTypeParser(1082, (val) => {
return `DATEONLY-${val}`;
});
@Nurul (Prisma) this code snipped should technically when reading from postgres convert db.Date differently than DateTime, which doesn't seem to work but it should. Maybe this is possible with @prisma/adapter-pg? This allows me when reviving the JSOn client side after it came in from http to be converted correctly by looking for the prefix "DATEONLY-"

Did you find this page helpful?