The code below works fine if the 2 dates are within the same year, but seems to break if the end date is in the following year. Could anyone point me in the right direction as to why?
Both vars are date pickers in the format DD/MM/YYYY.
Thanks in advance.
$(document).ready(function() {
$("#start").change( function() {
var startDate = $('#start').val().replace('/','');
var endDate = $('#due').val().replace('/','');
if(startDate > endDate){
$("#due").val($(this).val());
}
});
});
This comparison will only work if the dates are in format YYYY-MM-DD. If
val()is a string (in the format DD/MM/YYYY), you can do:Then you can compare them.