JQuery Moment Subtract Days to Date Example

By Hardik Savani December 25, 2020 Category : jQuery

This article goes in detailed on jquery moment subtract days. This post will give you simple example of jquery moment subtract 7 days. step by step explain how to subtract Days to current date in jquery. i explained simply about how to subtract days in date in moment js. you will do the following things for how to subtract 1 day in current date in jquery moment.

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: 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

Example 2: 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

I hope it can help you...

Tags :
Shares