If i have a variable that returns a date, in the format of dd MMM yyyy, so 28 Aug 2014, how can i get the date of the previous month.
I can modify the month via:
var myVariable = "28 Aug 2014"
var makeDate = new Date(myVariable);
makeDate = new Date(makeDate.setMonth(makeDate.getMonth() - 1));
Update:
A shorter version:
var myVariable = "28 Aug 2014"
var makeDate = new Date(myVariable);
console.log('Original date: ', makeDate.toString());
makeDate.setMonth(makeDate.getMonth() - 1);
console.log('After subtracting a month: ', makeDate.toString());
If you don't want to deal with corner cases just use moment.js. Native JavaScript API for Date is bad.