Why Do These Dates Result In 'Invalid Dates' After Being Fetched From MongoDb? Why Do These Dates Result In 'Invalid Dates' After Being Fetched From MongoDb? mongoose mongoose

Why Do These Dates Result In 'Invalid Dates' After Being Fetched From MongoDb?


2000-02-14 00:00:00.000Z is not a valid date format in Javascript.

ECMA Date Time String Format

YYYY-MM-DDTHH:mm:ss.sssZ

Ref date.

It is missing the T as in time element.

Try this in your console:

>> (new Date("2000-02-14 00:00:00.000Z")).toString()<< "Invalid Date"

vs.

>> (new Date("2000-02-14T00:00:00.000Z")).toString()<< "Mon Feb 14 2000 01:00:00 GMT+0100 (CET)"

Note, some browsers accept the former, such as Chrome, but it is non standard and by that follows pain as usual.

Firefox is rather strict on date.