Converting isodate to numerical value in MongoDB?


You can use getTime() for this. Following is the syntax −

yourVariableName.getTime();

Convert ISODate to numerical value −

> var arrivalDate=ISODate('2019-04-18 13:50:45');

Following is the query to convert ISODate to numerical value −

> arrivalDate.getTime();

This will produce the following output −

1555595445000

Let us verify that it is a correct numerical value for ISODate or not. Following is the query to get correct ISODate whenever we apply above numeric value −

> new Date(1555595445000);

This will produce the following output −

ISODate("2019-04-18T13:50:45Z")

Yes, this is a correct ISODate.

Updated on: 30-Jul-2019

341 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements