0

When creating dates from strings on the client side, if you use "-" as a separator (as in "2023-8-20" it seems to set the date to yesterday

> let x = new Date("2023-08-20"), y = new Date("2023/08/20")
  undefined

> x
  Sat Aug 19 2023 20:00:00 GMT-0400 (Eastern Daylight Time)

> y
  Sun Aug 20 2023 00:00:00 GMT-0400 (Eastern Daylight Time)

It also works fine if you do something like "2023, 08, 20" instead. I understand I could use <Date>.getTimezoneOffset() and add it to the hours of x to get it normal, but why does this happen?

This is not an issue on the server side from what I've tested so far.

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
karizma
  • 284
  • 2
  • 11
  • I replaced your image of code with the actual [formatted code](/help/formatting). In the future, please post the code itself instead of a screenshot. See [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/q/285551/843953) – Pranav Hosangadi Aug 23 '23 at 01:57

0 Answers0