Friday 28 February 2020

Does anyone know why the subtract method in Moment.js doesn't accept variables?

I have a for loop where I need to generate different dates and then look up data according to the dates: for (let j = 7; j > 0; j--) { let beginningOfDay = moment().startOf('day').subtract(j, 'days').toDate() let endOfDay = moment().endOf('day').subtract(j, 'days').toDate() console.log(j) console.log(beginningOfDay) When I run the code, with this block in it, my log statements show descending integers for the value of j, but the the beginningOfDay log is blank. This only happens when I use j as the 'amount' argument in the subtraction method. If I replace 'j' with '3', it works just fine.Why is that?

Submitted February 28, 2020 at 07:13PM by Briyo2289

No comments:

Post a Comment