JQuery Moment Subtract Year from Date Example

By Hardik Savani | December 30, 2020 | Category : jQuery


Now, let's see post of jquery moment subtract year. it's simple example of how to subtract year to current date in jquery. i explained simply about how to subtract years in date in moment js. This tutorial will give you simple example of how to subtract 1 year in current date in jquery moment. You just need to some step to done subtract year using moment.js.

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

let's see both example with output:

Example 1: Subtract Year to Date

<!DOCTYPE html>

<html>

<head>

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

</body>

<script type="text/javascript">

var startdate = '26-12-2020'

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

console.log(newDate);

</script>

</html>

Output:

26/12/2017

Example 2: Add Year to Date

<!DOCTYPE html>

<html>

<head>

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

</body>

<script type="text/javascript">

var startdate = '26-12-2020'

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

console.log(newDate);

</script>

</html>

Output:

26/12/2023

I hope it can help you...



Tags : jQuery Moment JS


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. 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, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: