I have this script,
var today = new Date();
var dd = today.getDate();
var ffffd = today.getDate()-1;
var ffffdd = today.getDate()-2;
var mm = today.getMonth()+
A convenient trick to get the end of last month is the take current date and use setDate(0)
. Then use that that to create a new date object and setDate(1)
for beginning of the month
var prevMonthEnd = new Date();
prevMonthEnd.setDate(0);
var beginLastMonth = new Date(prevMonthEnd);
beginLastMonth.setDate(1);
console.log([beginLastMonth.toString(), prevMonthEnd.toString()])