JQuery Moment Subtract Month Example

Admin   Jquery   208  2021-03-13 05:50:05

Hi Guys,

In this blog, i will show you example of jquery moment subtract month. We will talk about how to subtract month to current date in jquery. This article will give you simple example of how to subtract month in date in moment js. Here you will learn how to subtract 1 month in current date in jquery moment. Let's get started with subtract month using moment.js.

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.

So let's see both example with output:

Example 1: Subtract Month to Date

 

<!DOCTYPE html>

<html>

<head>

<title>JQuery Moment Add Month Example - NiceSnippets.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 - NiceSnippets.com</h1>

</body>

<script type="text/javascript">

var startdate = '26-01-2021'

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

console.log(newDate);

</script>

</html>

Output :

 

26/10/2020

Example 2: Add Month to Date

 

<!DOCTYPE html>

<html>

<head>

<title>JQuery Moment Add Month Example - NiceSnippets.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 - NiceSnippets.com</h1>

</body>

<script type="text/javascript">

var startdate = '26-01-2021'

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

console.log(newDate);

</script>

</html>

Output :

 

26/04/2021

It will help you....