Home > Enterprise >  Monthly recurring event on specific date
Monthly recurring event on specific date

Time:09-19

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

CodePudding user response:

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') );

CodePudding user response:

I solved it

dayjs().recur(dayjs().add(12, "month")).every(1, "month")
  • Related