Reputation: 149
I want to create a recurring date that repeats monthly
For e.g:
A user select a date “2022-09-16”
the ouput should be :
[“2022-09-16”, ”2022-10-16”,”2022-11-16”,”2022-12-16”]
I have no idea how to implement using dayjs and dayjs-recur
Any help would be appreciated
Upvotes: 1
Views: 394
Reputation: 28404
You can initiate a date by the starting day. After that iterate 3 times, and every time add one month to it then push a new string to the resulting array.
const getDates = str => {
const dates = [str];
const date = new Date(str);
for(let i = 0; i < 3; i++) {
date.setMonth(date.getMonth() + 1);
dates.push(date.toISOString().substring(0, 10));
}
return dates;
}
console.log( getDates('2022-09-16') );
Upvotes: 1