我在https://github.com/xdan/datetimepicker使用datetimepicker,它非常酷,我想检查一周(7天)内的日期范围,我尝试
if ($("#FromDate").val() + 7 > $("#ToDate").val()) {
alert("Please choose a week");
}
举例说明一些情况:
Fromdate: 27/10/2016 Todate: 31/10/2016 : OK
Fromdate: 27/10/2016 Todate: 2/11/2016 : OK
Fromdate: 27/10/2016 Todate: 3/11/2016 : show alert
但似乎不起作用。
最佳答案
我已经更新了答案,并且工作正常。单击此处jsFiddle
var fromDate = new Date($("#FromDate").val());
var sevenDate = new Date(fromDate.setDate(fromDate.getDate() + 7));
var toDate = new Date($("#ToDate").val());
if (sevenDate > toDate) {
alert("Please choose a week");
}