Forum Moderators: open
current_date = new Date();
current_date.setDate(current_date.getDate()-30);
current_month = current_date.getMonth();
current_month = current_month + 1;
current_day = current_date.getDate();
current_year = current_date.getYear();
var fulldate = "" + current_month + "/" + current_day + "/" + current_year;
document.getElementById("beginDate").value = fulldate;
Also, don't forget that you can pass an argument to the Date() function to determine which date to use. The argument passed must be a timestamp. JavaScript uses timestamps in 1000s of a second.
So, in this case, what you could do is simply:
current_date = new Date(new Date().getTime() - (30 * 24 * 60 * 60 * 1000));
Voila! Your
current_date variable is now set to a date 30 days ago. :)