Get previous date from given date in 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 : 




You might also like:

Functions in javascript

25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions.

How to submit form using javascript or jquery.

16-04-2017 javascript jquery submit form

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

How to find Angular Errors

06-03-2017 errors angularjs exceptionHandler

Get random strings from given string In javascript

21-02-2017 javascript random string