Use only the date1 part
In the following example only the date part is set. Time is set to by default to 00:00:00
. So the following query compares all entries archived within a day (2021-06-14
):
var start = new Date("2021-06-14");
var end = new Date("2021-06-15");
db.call_archive.find({
archivedAt: {$gte: start, $lt: end}
}).pretty();
Use both date and time
You can also specify the Time in ISO format
-
new Date("<YYYY-mm-ddTHH:MM:ss>")
- specifies the datetime in the client's local timezone and returns the ISODate with the specified datetime in UTC -
new Date("<YYYY-mm-ddTHH:MM:ssZ>")
- specifies the datetime in UTC and returns the ISODate with the specified datetime in UTC
var start = new Date("2021-06-14");
var end = new Date("2021-06-15");
db.call_archive.find({
archivedAt: {$gte: start, $lt: end}
}).sort({archivedAt: -1}).pretty(); //sort descending
Shared with ❤️ from Codever. 👉 Use the Copy to mine functionality to copy the snippet to your own personal collection and easy manage your code snippets.
Top comments (0)