if (Date.parse($("#startdate").val().replace("-", "/")) > Date.parse($("#enddate").val().replace("-", "/"))) { alert("起始日期要小於或等於截至日期"); return; }
注意日期格式轉化。
var myDate=new Date(); myDate.setFullYear(2008,8,9); var today = new Date(); if (myDate>today) { alert("Today is before 9th August 2008"); } else { alert("Today is after 9th August 2008"); }