Onclick event is failing capturing a future date. I keep receiving the custom error message stating, "the pending date has already passed."
This feature has worked in the past, and I could've sworn it worked at the end of 2018. Not sure why it's failing now.
Button click event:
$('#markPendingSubmit').on('click', function(){
var pendingDate = $('#reservationtime').val();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
console.log(pendingDate); // <-- correct prints user selected date (which is 01/09/2019)
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
if(pendingDate <= today)
{
$('#errorModal').modal('show');
$('.message').text('The pending date you selected has already passed. Please select a future pending date.');
return false;
}
else
{
// complete process
}
});
The user is attempting to set the 'pendingDate' to 1/09/2019, which is then compared to the variable 'today', but is failing because it's reading 1/09/2019 as a date that has already passed, even though today's date is 12/18/2018.
Why is this happening and how can I fix it?