I use the following code to check the date is before today! But when I select today, the condition becomes true!
var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
var today = new Date();
if(today >= fromDate || toDate <= today){
alert('Cannot book dates prior to today.');
$('#from, #to').val('')
return false;
}
What am I doing wrong here?
Should be something like
var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
var today = new Date();
today.setHours(0,0,0,0);
fromDate.setHours(0,0,0,0);
toDate.setHours(0,0,0,0);
if(today > fromDate || toDate < today){
alert('Cannot book dates prior to today.');
$('#from, #to').val('')
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.