Post

Ugh! Wrestling with dates and timezones again. How do you store date values from users in a DB? HTML date input sends values as YYYY-MM-DD. This does not include timezones and is not ISO format. When converted to a Date object, it defaults to GMT, which means the user sees the wrong date

0 reposts0 likes

If you can modify the client side date values before sending to the server, try saving an ISO date string. I.e., create a temporary Date object (new Date), set Date, FullYear, and Month fields (month is 0-indexed btw) with the yyyy-mm-dd parts, then save what toISOString() returns.

Thanks. I'm considering that option. The other is to just leave is as the YYYY-MM-DD string in the DB. It feels like the ISO dateis better, but I'm not sure how to get that without either a datetime input or client side js

Not foolproof, you’ll need to format ISO values from server if you’re not already doing that - which might be a question for the team - unless, of course, you’re it. UTC could come up too but wait until you have this or other solution under control first. LMK how it goes