我正在使用jQuery比较jasper服务器中的两个日期,但它没有比较

时间:2014-06-17 10:21:50

标签: jquery jsp jasperserver

使用jQuery比较jasper服务器中的两个日期,但它没有比较这些日期。首先,我将这两个日期存储到两个不同的变量中,如

var fromDate = document.querySelector('#FromDate label.control input').value;
var toDate = document.querySelector('#ToDate label.control input').value;

现在将两个日期比较为

if(fromDate>toDate){
    alert("To date should be greater than from date");
return false;
}

当我们有同一天像天堂是#34; 01-07-2013"它工作正常和todate是" 01-06-2013"它显示错误,但如果我改变像fromdate是" 11-07-2013"和todate是" 21-06-2013"它不会显示错误,而是显示报告。

1 个答案:

答案 0 :(得分:0)

var fromDate ="11-09-2013";
var toDate ="21-06-2013";
var dtfrom   = parseInt(fromDate.substring(0,2),10); 
var monfrom  = parseInt(fromDate.substring(3,5),10);
var yrfrom   = parseInt(fromDate.substring(6,10),10); 
var dtto   = parseInt(toDate.substring(0,2),10); 
var monto  = parseInt(toDate.substring(3,5),10); 
var yrto   = parseInt(toDate.substring(6,10),10); 
monfrom = monfrom -1 ;
monto = monto -1 ;
var date1 = new Date(yrfrom, monfrom, dtfrom); 
var date2 = new Date(yrto, monto, dtto); 
if(date1 > date2)
 {
  alert("To date should be greater than from date");
  return false;
}

演示:

http://jsfiddle.net/rmtGS/1/