Mongodb $dayOfMonth with timezone

I need to get day of month in mongo in local timezone. Now if i run

$dayOfMonth : ISODate("2017-10-19T00:00:00.000+01:00")

i get 18, but i need that in local timezone. Is there any way how to force mongo to use local timezone with $dayOfMonth? Or at least how to get timezone offset in mongo?

Upvotes: 0

Views: 973

Answers (1)

s7vr
s7vr

Reputation: 75964

You can try the below aggregation in 3.6 which adds the timezone support for all date operators.

db.collection_name.aggregate({
  "dayOfMonth": {
    "$dayOfMonth": {
      "date": "$date",
      "timezone": "Europe/Amsterdam"
    }
  }
})

Upvotes: 1

Related Questions