2020-06-01

MongoDB - Extract year, month and day from a date field

{"$addFields": {

  "year": {
    "$year": {
      "date": "$date_field_name_here",
      "timezone": "America/Detroit"
    }
  },

  "month": {
    "$month": {
      "date": "$date_field_name_here",
      "timezone": "America/Detroit"
    }
  }

  "day": {
    "$dayOfWeek": {
      "date": "$date_field_name_here",
      "timezone": "America/Detroit"
    }
  }
  
}}

No comments:

Post a Comment