how to compare two datepicker date jquery

Can I suggest auto limiting your dates instead? In this example the 2nd combo box won't allow you to pick a lower date than the one you pick on the fisrt one.

$(document).ready(function(){

  $("#txtFromDate").datepicker({

      numberOfMonths: 2,

      onSelect: function(selected) {

        $("#txtToDate").datepicker("option","minDate", selected)

      }

  });

  $("#txtToDate").datepicker({

      numberOfMonths: 2,

      onSelect: function(selected) {

         $("#txtFromDate").datepicker("option","maxDate", selected)

      }

  }); 

});

Here is a working demo


You need to use this to get the day/month/year

var day1 = $("#datepicker").datepicker('getDate').getDate();                 
        var month1 = $("#datepicker").datepicker('getDate').getMonth() + 1;             
        var year1 = $("#datepicker").datepicker('getDate').getFullYear();

After that you can compare the values.


Date.parse(fromDate) > Date.parse(toDate)

Example

var sDate = $('#EFT_FRM_DATE').val();
var eDate = $('#EFF_TO_DATE').val();

if (Date.parse(sDate) > Date.parse(eDate) || Date.parse(sDate) == Date.parse(eDate)) {
   ShowMessage(CurrencySetupExchangeIndex.EndDateGreaterStartDate, 'Error');
   //alert
   return false;
   return;
}

simplified statement:

if (Date.parse(sDate) >= Date.parse(eDate)) {...