Get previous date from given date in javascript

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:

Convert and download html to pdf without saving file

28-10-2018 node js convert html to pdf pdf download pdf without saving

How to upload file by using request module

18-03-2017 request module node js

Get previous date from given date in javascript

06-03-2017 date javascript previous date

How to find Angular Errors

06-03-2017 errors angularjs exceptionHandler

How to change background color and color to the text using javascript

27-02-2017 css javascript colors