Get previous date from given date in javascript

06-03-2017 date javascript previous date

We need to substract one day for the given date.  The given date is '24-03-2017'.  By using the below javascript code get previous date.

var date = '24-03-2017';
var nextday = new Date(date.setTime( date.getTime() - 1 * 86400000 ));
var day = nextday.getDate();
var months = (nextday.getMonth() + 1);
// Months use 0 index.		
var nextdate= nextday.getFullYear()+'-'+(months[1] ? month :  '0'+ months[0]) + '-' +  (day[1] ? day :  '0'+ day[0]);	

 

The result is : 

 

 

22-03-2017

You might also like:

Use java script file client side and server side at a time in node js
30-07-2017 node js include call javascript
Time Sorting Ascending or Descending Order in Javascript
19-07-2017 Javascript ascending order descending order
How to use http-post request in node js
14-03-2017 http-post module node js
Remove last two characters from given string
06-03-2017 substring javascript remove
How to set or update or push the values into Object in javacript
27-02-2017 javascript set update push object