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
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!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.Thanks for taking the time to respond, got my answer to store and read using ISO 8601
No worries! Happy to help 🙂