P
Prisma•2mo ago
Wojak

Question about storing/reading dates from database

Hi, does anyone got some links or know how should I deal with dates in JavaScript/Prisma when it comes to storing it to the db and reading a date DateTime db value? My colleague from another timezone gets -1 day when displaying it from the client while mine shows the correct value. I store it using new Date(value.someDatefield) upon form submission and read it using date.getFullYear/getDate/getMonth.
4 Replies
Prisma AI Help
Prisma AI Help•2mo ago
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Nurul
Nurul•2mo ago
I would recommend using ISO 8601 format strings (YYYY-MM-DDTHH:mm:ssZ) when creating dates to ensure consistency. Instead of using getFullYear(), getDate(), and getMonth(), consider using toISOString() or a date formatting library like date-fns to ensure consistent representation across timezones. Besides that store all dates in UTC format in the database.
Wojak
WojakOP•2mo ago
Thanks for taking the time to respond, got my answer to store and read using ISO 8601
Nurul
Nurul•2mo ago
No worries! Happy to help 🙂

Did you find this page helpful?