JQuery Moment Subtract Month Example
Are you looking for example of jquery moment subtract month. Here you will learn 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.
let's see both example with output:
Example 1: 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
Example 2: 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
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Moment Subtract Days to Date Example
- JQuery Moment Add Days to Date Example
- JQuery Moment Get Current Date Example
- Laravel Carbon Add Days to Date Example
- How to Install and Use Moment JS in Laravel?
- Angular Change Date Format in Component Example
- How to Change Date Format in Codeigniter?
- How to Change Date Format using Moment in Vue JS?
- How to Change Date Format in JQuery?
- Bootstrap Timepicker using Datetimepicker JS Example