I´m trying to traverse dates from a given start date. I'm stuck with the eternal problem around nodeJS and async programming:
getdates('2018-08-01', function(result) {
console.log(result);
})
function getdates (startdate, callback) {
let now = new Date();
let start = new Date(startdate);
let Dates = [];
do {
Dates.push(start);
start.setDate(start.getDate() + 1);
}
while(now.getDate() != start.getDate())
callback(Dates);
}
The result of this is:
[ 2018-08-07T00:00:00.000Z, 2018-08-07T00:00:00.000Z, 2018-08-07T00:00:00.000Z, 2018-08-07T00:00:00.000Z, 2018-08-07T00:00:00.000Z, 2018-08-07T00:00:00.000Z ]
An array with only today's date.
I know is because of the nature of NodeJS, but how can I solve this or do it the right way?
Best regards, Christian