close

How to properly add 1 month from now to current date in moment.js

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to properly add 1 month from now to current date in moment.js in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to properly add 1 month from now to current date in moment.js ?

  1. How to properly add 1 month from now to current date in moment.js ?

    properly add 1 month from now to current date in moment.js You could try
    moment().add(1, 'M').subtract(1, 'day').format('DD-MM-YYYY')

  2. properly add 1 month from now to current date in moment.js

    properly add 1 month from now to current date in moment.js You could try
    moment().add(1, 'M').subtract(1, 'day').format('DD-MM-YYYY')

Method 1

var currentDate = moment('2015-10-30');
var futureMonth = moment(currentDate).add(1, 'M');
var futureMonthEnd = moment(futureMonth).endOf('month');

if(currentDate.date() != futureMonth.date() && futureMonth.isSame(futureMonthEnd.format('YYYY-MM-DD'))) {
    futureMonth = futureMonth.add(1, 'd');
}

console.log(currentDate);
console.log(futureMonth);

EDIT

moment.addRealMonth = function addRealMonth(d) {
  var fm = moment(d).add(1, 'M');
  var fmEnd = moment(fm).endOf('month');
  return d.date() != fm.date() && fm.isSame(fmEnd.format('YYYY-MM-DD')) ? fm.add(1, 'd') : fm;  
}

var nextMonth = moment.addRealMonth(moment());

Method 2

You could try

moment().add(1, 'M').subtract(1, 'day').format('DD-MM-YYYY')

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment