I am trying to retrieve a date but I am struggling with the month because January = 0 instead of 1. I need to retrieve items which occured after today -60 days.
var today = new Date();
if (today.getMonth() < 1) {
var numberOfDaysLastMonth = getDaysInMonth(12,today.getFullYear()-1); //number of days in december last year
var numberOfDaysThisMonth = getDaysInMonth(today.getMonth()+1,today.getFullYear()); //number of days this month
} else {
var numberOfDaysLastMonth = getDaysInMonth(today.getMonth(), today.getFullYear()); //number of days last month
var numberOfDaysThisMonth = getDaysInMonth(today.getMonth()+1, today.getFullYear()); //number of days this month
};
var startDate = new Date();
var myMonth;
var myYear;
if (today.getMonth() < 1) {
myMonth = today.getMonth() + 1;
myYear = today.getFullYear()-1;
} else {
myMonth = startDate.getMonth()-1;
myYear = today.getFullYear();
};
startDate = myYear+"-"+myMonth+"-"+startDate.getDate(); // returns last month
Is there a more simple (and working) way to do this?