JQuery Moment Add Days to Date Example

Hello,

This tutorial will provide example of jquery moment add days. i would like to share with you jquery moment add 7 days. Here you will learn how to add Days to current date in jquery. i explained simply step by step how to add days in date in moment js.

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

let’s see both example with output:

Example 1: Add Days to Date:

<!DOCTYPE html>

<html>

<head>

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

</body>

<script type="text/javascript">

var startdate = '26-12-2020'

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

console.log(newDate);

</script>

</html>

Output:

29/12/2020

Example 2: Subtract Days to Date:

<!DOCTYPE html>

<html>

<head>

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

</body>

<script type="text/javascript">

var startdate = '26-12-2020'

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

console.log(newDate);

</script>

</html>

Output:

23/12/2020

I hope it can help you…

Leave a Comment