[MongoDB] Getting year-month-day string from ISODate

Tadashi Shigeoka ·  Tue, December 6, 2016

To get just the year-month-day part as a string from MongoDB’s ISODate, you can get it with code like the following using toISOString() and substring().

MongoDB | モンゴディービー

now = ISODate()
// ISODate("2016-12-06T05:02:20.675Z")

now.toISOString().substring(0, 10)
// 2016-12-06

I wanted to use just the year-month-day, so I’m keeping this as a personal memo article.

You could also use slice() instead of substring(). That’s up to your preference.

That’s all from the Gemba.