2017-05-28 58 views
0
function CompareDate(epr_departuredate,epr_returneddate) { 
    var epr_departuredate = new Date(24,11,2016); //Today Date 
    var epr_returneddate = new Date(25,11,2016); 
    if (epr_departuredate >epr_returneddate) { 

     alert("Departure Date Cannot Late Than Return Date. Please Check"); 
    }else { 
     alert("Date You Enter is Valid. Please Continue."); 
    } 
} 

爲什麼我的代碼不工作,只顯示:出發和返回的日期

出發日期不能遲到總比不到返程日期。請檢查。

當我跑步。我只想比較出發日期和返回日期。

+7

這是'新的日期(年,月[日期[,小時,分鐘,秒[毫秒]]]]]);'[來源] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)] –

回答

1

您可以檢查此:

function CompareDate(epr_departuredate,epr_returneddate) { 
    epr_departuredate="2017/05/28";//say it is string and pass this value when call the function 
    epr_returneddate="2017/05/29" 
    var departuredate = new Date(epr_departuredate); //Today Date 
    var returneddate = new Date(epr_returneddate); 
    if (departuredate >returneddate) { 

     alert("Departure Date Cannot Late Than Return Date. Please Check"); 
    }else { 
     alert("Date You Enter is Valid. Please Continue."); 
    } 
} 
+0

謝謝你的回答。可悲的是它仍然顯示第二個條件,即使我錯誤地輸入日期。 – typo

+0

當您調用CompareDate函數時,請告訴我使用哪種日期格式 –

+0

@typo,因爲您需要刪除分配固定值的行(僅針對測試完成)並將正確的值傳遞給該函數。 –