JQuery Moment Add Month to Date Example

Hi,

Today our leading topic is jquery moment add month. this example will help you jquery moment add 7 month. This article will give you simple example of how to add month to current date in jquery. we will help you to give example of how to add month in date in moment js. You just need to some step to done how to add 1 month in current date in jquery moment.

Here, i will give you simple example of jquery moment js add() method for add month to date and jquery moment js subtract() method for subtract month from date.

let’s see both example with output:

Example 1: Add Month to Date

<!DOCTYPE html>

<html>

<head>

<title>JQuery Moment Add Month Example - ItSolutionStuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>

</head>

<body>

<h1>JQuery Moment Add Month Example - ItSolutionStuff.com</h1>

</body>

<script type="text/javascript">

var startdate = '26-12-2020'

var newDate = moment(startdate, "DD-MM-YYYY").add(3, 'months').format('DD/MM/YYYY');

console.log(newDate);

</script>

</html>

Output:

26/03/2021

Example 2: Subtract Month to Date

<!DOCTYPE html>

<html>

<head>

<title>JQuery Moment Add Month Example - ItSolutionStuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>

</head>

<body>

<h1>JQuery Moment Add Month Example - ItSolutionStuff.com</h1>

</body>

<script type="text/javascript">

var startdate = '26-12-2020'

var newDate = moment(startdate, "DD-MM-YYYY").subtract(3, 'months').format('DD/MM/YYYY');

console.log(newDate);

</script>

</html>

Output:

26/09/2020

I hope it can help you…

Leave a Comment