In a project of mine, I have two fields set to datepicker
(jQuery UI). Only the first one is editable ( InitialDate
). The second ( FinalDate
) must have the same value of InitialDate
plus a year.
If I use the following code:
<script>
$(document).ready(function () {
$("#InitialDate").change(function () {
var d = $.datepicker.parseDate('dd/mm/yy', $(this).val());
d.setFullYear(d.getFullYear() + 1);
$('#FinalDate').datepicker('setDate', d);
});
});
</script>
The script sums wrong. The date is five days less.
Searching, I found that I have to modify the code for something like this:
<script>
$(document).ready(function () {
$("#InitialDate").change(function () {
var d = $.datepicker.parseDate('dd/mm/yy', $(this).val());
var year = parseInt(1, 10);
d.setFullYear(d.getFullYear() + year);
$('#FinalDate').datepicker('setDate', d);
});
});
</script>
Why?