0
$("#EndDate").change(function () {
    var startDate = document.getElementById("StartDate").value;
    var endDate = document.getElementById("EndDate").value;
    if ((Date.parse(endDate) <= Date.parse(startDate))) {
        alert("End date should be greater than Start date");
        document.getElementById("EndDate").value = "";
    }
});

If I used this logic, It doesn't work when I pick the date from the datepicker, If I wrote the date manually in the textbox this logic is working. Can any one have a fix for this.

j08691
  • 204,283
  • 31
  • 260
  • 272
Dpu
  • 1
  • 2

1 Answers1

0

You can use $.datepicker to get the date. If you use datepicker to select a date, parsing it as text may not be the best way.

$(selector).datepicker("getDate") will return you an actual time object.

In your case:

if ($("#StartDate").datepicker("getDate") >= $("#EndDate").datepicker("getDate")) {
  alert("End date should be greater than Start date");
  $("#EndDate").val("");
}

This is a working example: https://jsfiddle.net/1qo9be6s/

Nomenator
  • 1,021
  • 1
  • 13
  • 28
  • $("#addvalidations").click(function () { if ($("#txtFromDate").datepicker("getDate") >= $("#txtToDate").datepicker("getDate")) { alert("End date should be greater than Start date"); $("#txtToDate").val(""); } }); – Dpu Apr 07 '15 at 14:51