In this tutorial, We will learn how to momentJS to subtract month. We will talk about how to subtract month to the current date in jquery.
Lets learn by example:
<!DOCTYPE html>
<html>
<head>
<title>JQuery Moment Add Month Example</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</h1>
</body>
<script type="text/javascript">
var startdate = '26-02-2021';
//how many month you want to substract
//I want 1 month
var newDate = moment(startdate, "DD-MM-YYYY").subtract(1, 'months').format('DD/MM/YYYY');
document.write(newDate);
</script>
</html>
Output:
26/01/2021 |
Thanks, May this example will help you...