Possible Duplicate:
Finding date by subtracting X number of days from a particular date in Javascript
I have a jQuery datepicker which allows users to pick a Friday from any given week. I want to populate fields based off that Friday and input the dates from Mon-Thurs as well.
I.e. the user picks this coming Friday (10-26-2012), I want to subtract from the day by 1 to get Thursday date, and then Wed, etc etc.
How would I approach this?
$(document).ready(function(){
$("#friDate").Zebra_DatePicker({
format: 'm-d-Y',
disabled_dates: ['* * * 0-4,6'],
first_day_of_week: 0,
onSelect: function(){
var date = $("#friDate").val();
$("#mon").val('INSERT MON DATE');
$("#tue").val('INSERT TUE DATE');
$("#wed").val('INSERT WED DATE');
$("#thu").val('INSERT THU DATE');
$("#fri").val(date);
}
});
});
Any help is greatly appreciated! Thanks :).
To subtract a day from an existing date, just subtract the number of milliseconds in a day.
So for your code, you could do the following
UPDATE Though my code works, Waxen’s solution is simpler and I would use that. I’ll leave this answer here for reference