Julian
Julian

Reputation: 1831

Convert String to Date in MongoDB

How do I convert a String like "11/21/2012" to Date in MongoDB?

I tried the following

obj.as_from = ISODate("11/21/2012");

and got this error

uncaught exception: invalid ISO date

Is there a simple way to convert the string above?

Upvotes: 2

Views: 5016

Answers (2)

Hao Luong
Hao Luong

Reputation: 102

You try doing like that:

ISODate("11-21-2012T05:00:00.000Z")

Upvotes: 0

Rafa Viotti
Rafa Viotti

Reputation: 10530

As pointed by user602525, in the Mongo shell.

obj.as_from = new Date("11/21/2012");

Do not forget to use the new operator.

Upvotes: 4

Related Questions