Reputation: 1165
I've been trying to add a month to a date for a while now but I can't do it and I have no idea why:
My JSON:
{
"module": "C Graphical Programming",
"project": "Back To The Future - MyHunter",
"start": "2020-12-14",
"end": "2021-01-03",
"bttf": true
}
My code:
timeLineRaw.projects.forEach(element => {
let timeLineEmbed = new Discord.MessageEmbed();
timeLineEmbed.setTitle("Test");
let projectStart = moment(element.start);
let projectStartPlusOneMonth = projectStart.add(1, 'months');
if (moment(actual).isAfter(projectStart) && moment(actual).isBefore(projectStartPlusOneMonth)) {
timeLineEmbed.addField(`${element.module} - ${element.project}`, element.start);
channel.send(timeLineEmbed);
db.get('projects').remove({project: element.project}).write();
}
});
The output of projectStart
and projectStartPlusOneMonth
from debugger:
Moment<2020-12-09T00:00:00+01:00> Moment<2020-12-09T00:00:00+01:00>
And if I try to add 1 month to actual date like this moment().add(1, 'months')
this works...
Upvotes: 0
Views: 624
Reputation: 655
try this
var start= "2020-12-14";
var dt = moment(start);
var futureMonth = moment(dt).add(1, 'M');
console.log(futureMonth)
Upvotes: 0
Reputation: 136
Wrap the variable in another reference of moment like this:
moment(projectStart).add(1, 'months');
moment needs to be referenced everytime that it's used.
Upvotes: 1