I’m trying to get the second latest full hour. So if the time is 15:30 now, I’m trying to get 14:00, so I basically need to truncate the current minutes and then furthermore truncate an hour..
I’m trying to project the date like this:
// Let's say the current time is 15:46
"period": {
"start": 2022-11-03T14:00:00.000,
"end": 2022-11-03T15:00:00.000
}
It’s gonna be something like this:
{
$project: {
period: {
start: {
"$subtract": [ {
$hour: {
"$toDate": "$$NOW"
}
}, 1 ]
},
end: {
"$subtract": [ {
$hour: {
"$toDate": "$$NOW"
}
}, 1 ]
},
}
}
How do I do that?
2
Answers
I’m not sure i understood well… But, in case, maybe something like this?
https://mongoplayground.net/p/9xALfPpdSdS
Do you mean this one?