I am confused why on converting 8/20/2021 to ISO (cosmosDB format) I am getting 2021-08-19T18:30:00.000Z
const event = new Date('8/20/2021');
console.log(event.toISOString()); //"2021-08-19T18:30:00.000Z"
all the date are saved as string in my cosmosdb and hence I was not able to filter based on given date range and as result we ended up converting string to Date but now when I am trying to convert in to cosmos db expected format it gives me incorrect or may be correct date to update my database.
should I go ahead and update DB to 2021-08-19T18:30:00.000Z in place of 8/20/2021? or it should be 2021-08-20T00:00:00.000Z?
The value you are passing to Date() is vague. It's being parsed as a date for the timezone for the computer's locale.
When you convert to an ISO string, it's being displayed in UTC, which is 5 and a half hours behind that local time zone.
Date()The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC
Try this
const event = Date.parse('8/20/2021');
console.log(event) // expected output: 818035920000
Now you can store that in your db.