I was trying mongoExport with some date condition, I read here that date has to be in epoch format.
Question is,
I tried below,
> new Date(2013,10,16)
ISODate("2013-11-16T00:00:00Z")
Assuming that I gave Oct-16-2013, But it returned me '2013-11-16'. Same with epoch format also.
> new Date(2013,10,16)*1
1384560000000
>
> new Date(1384560000000)
ISODate("2013-11-16T00:00:00Z")
Can you please help, why its changing the month to 11 ?
You can specify a particular date by passing an ISO-8601 date string with a year within the inclusive range 0 through 9999 to the new Date() constructor or the ISODate() function. These functions accept the following formats: new Date("<YYYY-mm-dd>") returns the ISODate with the specified date.
ISODate("2012-12-19T06:01:17.171Z") ISODate() is a helper function that's built into to MongoDB and wraps the native JavaScript Date object. When you use the ISODate() constructor from the Mongo shell, it actually returns a JavaScript Date object.
If you have documents that store dates as Date objects, but you want to return them in a different format, you can use the $dateToString aggregate pipeline operator. The $dateToString operator converts the Date object to a string, and optionally allows you to specify a format for the resulting output.
The month
parameter of JavaScript's Date
constructor is 0-based. So 0 for January to 11 for December, making it 9 for October instead of 10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With