How can I calculate dates in jQuery, and set an input date's value to that?
I have this html:
-
<input class="smalldatepicker" type="date" id="datepickerFrom" value="2016-09-04">
</input>
<label class="cccsfont"> to </label>
<input type="date" class="smalldatepicker" id="datepickerTo" value="2016-09-10">
</input>
Which sets "datepickerTo" to the last Saturday (this is based on today's date of Thursday, 9/15) and "datepickerFrom" to the Sunday before that.
This is manually added, though; I want to do it programmatically, in jQuery, something like:
-
var lastSat = getLastSaturday(); // return in form "YYYY-MM-DD"
var sundayBeforeLastSat = getSundayBeforeLast(lastSat); // " "
$("#datepickerTo").val(lastSat);
$("#datepickerFrom").val(sundayBeforeLastSat);
I think this should work, but I don't know what to put in the functions:
- function getLastSaturday() {
return ???;
}
function sundayBeforeLastSat(lastSat) {
return ???;
}