When working on Mongo Shell, I need to format currentDate to a ISODateĀ format String YYYY-MM-DD
var formatDate = function (date) {
day = date.getDate();
reportdate = date.getFullYear();
month = date.getMonth() + 1;
if (month < 10) {
reportdate = reportdate + “-0” + month;
} else {
reportdate = reportdate + “-” + month;
}
if (day < 10) {
reportdate = reportdate + “-0” + day;
} else {
reportdate = reportdate + “-” + day;
}
return reportdate;
}
var date = new ISODate(“2021-01-01T05:00:00.000Z”);
print(formatDate(date));