Search code examples
stringmongodbdateisodate

How can I store date prior to B.C in MongoDB as ISODate?


In MongoDB I've stored dates prior to B.C has String type. How can I stored in ISODate() type ?

I've tried this :

db.test.insert({"date" : new ISODate("-63-09-23") })

but I get an error :

uncaught exception: invalid ISO date

Thanks for your help !


Solution

  • The MongoDB IsoDate() is just a wrapper around the normal javascript Date, which can take dates to 100 million days before 1970, so something like setFullYear() is probably what you need - like this: Can you create dates that are lower than 271800 BC? Like dinosaur time?