Hi to everybody,
for my query i need to create an calendar array for store all days between two input dates. For example:date1:ISODate("2018-02-12)
and date2:ISODate("2018-03-12)
, in output i want a document like this:
days:[
{day:"2018-02-12T00:00:00.000Z"},
{day:"2018-02-13T00:00:00.000Z"},
{day:"2018-02-14T00:00:00.000Z"},
{day:"2018-02-15T00:00:00.000Z"},
{day:"2018-02-16T00:00:00.000Z"},
{day:"2018-02-17T00:00:00.000Z"},
{day:"2018-02-18T00:00:00.000Z"},
{day:"2018-02-19T00:00:00.000Z"},
{day:"2018-02-20T00:00:00.000Z"},
{day:"2018-02-21T00:00:00.000Z"},
{day:"2018-02-22T00:00:00.000Z"},
{day:"2018-02-23T00:00:00.000Z"},
{day:"2018-02-24T00:00:00.000Z"},
{day:"2018-02-25T00:00:00.000Z"},
{day:"2018-02-26T00:00:00.000Z"},
{day:"2018-02-27T00:00:00.000Z"},
{day:"2018-02-28T00:00:00.000Z"},
{day:"2018-03-01T00:00:00.000Z"},
{day:"2018-03-02T00:00:00.000Z"},
{day:"2018-03-03T00:00:00.000Z"},
{day:"2018-03-04T00:00:00.000Z"},
{day:"2018-03-05T00:00:00.000Z"},
{day:"2018-03-06T00:00:00.000Z"},
{day:"2018-03-07T00:00:00.000Z"},
{day:"2018-03-08T00:00:00.000Z"},
{day:"2018-03-09T00:00:00.000Z"},
{day:"2018-03-10T00:00:00.000Z"},
{day:"2018-03-11T00:00:00.000Z"},
{day:"2018-03-12T00:00:00.000Z"},
I have a solution if the two dates are in the same month but if i have different months o years my code doesn’t work. My code is the following:
{set:{
dates:{
$map:{
input:
{
$range:
[0,
{$subtract:[{$add:[1,"$endDate"]}, "$startDate"]},
1000*60*60*24]
},
in:{$add:["$startDate","$$this"]}
}}
}
}
I want this because at the end i compare this calendar with another calendar2 and check if all days between the two input dates are presents in calendar2.
Thank you