Reputation: 391
I need to convert a date to a format "Mon Oct 17 09:00:00 IST 2016" to 2016-10-17
my query is like this:
db.collection.aggregate( [ { $project: { yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date:new Date("Mon Oct 17 09:00:00 IST 2016") } } } }] )
How can I achieve that through a mongo query Kindly help me.
Upvotes: 0
Views: 833
Reputation: 3729
Please use "dateToString" in aggregate also check Link
Ex: $date is Your Date to Convert.
db.Collection.aggregate(
[
{
$project: {
yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date: "$date" } }
}
}
]
)
Upvotes: 1