Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get days months and years between dates mongodb

db.collection.aggregate([
  {
    $project: {
      Start: "$start",
      End: "$end",
      years: {
        $dateDiff: {
          startDate: "$start",
          endDate: "$end",
          unit: "year"
        }
      },
      months: {
        $dateDiff: {
          startDate: "$start",
          endDate: "$end",
          unit: "month"
        }
      },
      days: {
        $dateDiff: {
          startDate: "$start",
          endDate: "$end",
          unit: "day"
        }
      },
      _id: 0
    }
  }
])
Source by mongoplayground.net #
 
PREVIOUS NEXT
Tagged: #days #months #years #dates #mongodb
ADD COMMENT
Topic
Name
5+9 =