[Solved] Comparing two textboxes with datetime value in jquery


Something like this ?

 function onChange(sender, txt, departed) 
 {
    var txtArrival = $("#txtArrivalDate");
    var txtArrivalDate = $(txtArrival).val(); //Value from arrival
    var txtDate = $(txt).val(); //Value from departed
    
    var departureDate = new Date(txtDate); //Converting string to date
    var arrivalDate = new Date(txtArrivalDate); //Converting string to date

    

    if (departureDate.getTime() < arrivalDate.getTime()) {
         txt.val(txtArrivalDate); //Does not work, value is not updated
    }
}

$("#txtDepartureDate").change(function(event){
  onChange(event, $("#txtDepartureDate"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" id="txtArrivalDate" />
<input type="date" id="txtDepartureDate" />

0

solved Comparing two textboxes with datetime value in jquery