[MongoDB]: How to truncate/chop off time-stamp from Date
How to truncate/chop off time-stamp from Date
> db.dbversity.find({},{tradeDate:1})
{ “_id” : “1”, “tradeDate” : ISODate(“2015-06-25T18:30:00Z”) }
{ “_id” : “2”, “tradeDate” : ISODate(“2015-06-25T18:30:00Z”) }
{ “_id” : “3”, “tradeDate” : ISODate(“2015-06-24T18:30:00Z”) }
{ “_id” : “4”, “tradeDate” : ISODate(“2015-06-23T18:30:00Z”) }
{ “_id” : “5”, “tradeDate” : ISODate(“2015-06-23T18:30:00Z”) }
{ “_id” : “6”, “tradeDate” : ISODate(“2015-06-24T18:30:00Z”) }
{ “_id” : “7”, “tradeDate” : ISODate(“2015-06-25T18:30:00Z”) }
{ “_id” : “8”, “tradeDate” : ISODate(“2015-06-24T18:30:00Z”) }
>
>
> db.dbversity.aggregate(
… [
… {
… $project:{
… “date” : {
… “$subtract” : [
… “$tradeDate”,
… {
… “$add” : [
… {“$millisecond” : “$tradeDate”},
… { “$multiply” : [ {“$second” : “$tradeDate”}, 1000 ] },
… { “$multiply” : [ {“$minute” : “$tradeDate”}, 60, 1000 ] },
… { “$multiply” : [ {“$hour” : “$tradeDate”}, 60, 60, 1000 ] }
… ]
… }
… ]
… }
… }
… }
… ]
… )
{ “_id” : “1”, “date” : ISODate(“2015-06-25T00:00:00Z”) }
{ “_id” : “2”, “date” : ISODate(“2015-06-25T00:00:00Z”) }
{ “_id” : “3”, “date” : ISODate(“2015-06-24T00:00:00Z”) }
{ “_id” : “4”, “date” : ISODate(“2015-06-23T00:00:00Z”) }
{ “_id” : “5”, “date” : ISODate(“2015-06-23T00:00:00Z”) }
{ “_id” : “6”, “date” : ISODate(“2015-06-24T00:00:00Z”) }
{ “_id” : “7”, “date” : ISODate(“2015-06-25T00:00:00Z”) }
{ “_id” : “8”, “date” : ISODate(“2015-06-24T00:00:00Z”) }
>
>