Thursday, October 3, 2019

Mongodb aggregate: convert date to another timezone

Mongo version 3.6 timezone operator in  dateToString

Mongo version 3.4 DateToString and Add:

project()
.and(DateOperators.DateToString.dateOf(ArithmeticOperators.Add.valueOf(DATE).add(offsetMilliseconds))
.toString("%Y-%m-%d")).as(DATE_DAYS);


"dateDays": {
"$dateToString": {
"format": "%Y-%m-%d",
"date": {
"$add": ["$date", -36000000]
}
}
}

No comments: