Can I get today’s date plus one month in moment js? [duplicate]

<ion-datetime displayFormat="MMMM YY" min="{{min}}" max="{{max}}"></ion-datetime>

Now you need the min and max value.

First, let find out today and next month.

const today     = moment(new Date()).format('YYYY-MM-DD');

const nextMonth = moment(today).add(1, 'M');
var nextMonthEnd = moment(nextMonth).endOf('month');

if(today.date() != nextMonth.date() && nextMonth.isSame(nextMonthEnd.format('YYYY-MM-DD'))) {
    nextMonth = nextMonth.add(1, 'd');
}

console.log(today.format('DD-MM-YYYY'));
console.log(nextMonth.format('DD-MM-YYYY'));

Now

this.min = this.today;

this.max = this.nextMonth

Leave a Comment