Answers for "mongodb time gap between two timestamps"

0

mongodb time gap between two timestamps

// { _id: 1, start: ISODate("2015-08-24T00:00:00Z"), end: ISODate("2015-08-24T07:00:00Z") }
// { _id: 2, start: ISODate("2015-08-24T20:00:00Z"), end: ISODate("2015-08-25T01:00:00Z") }
db.collection.aggregate([
  { $project:
    { duration:
      { $dateDiff: { startDate: "$start", endDate: "$end", unit: "hour" } }
    }
  }
])
// { "_id" : 1, "duration" : 7 }
// { "_id" : 2, "duration" : 5 }
Posted by: Guest on July-26-2021
0

mongodb time gap between two timestamps

db.collectionname.aggregate([
  {$project: {
      duration: {$divide: [{$subtract: ["$endtime", "$starttime"]}, 3600000]}
  }}
])
Posted by: Guest on July-26-2021

Code answers related to "mongodb time gap between two timestamps"

Browse Popular Code Answers by Language