Friday, 17 June 2016

jQuery Compare start and end times

For compare times in jQuery first you need to parse it with Date.Parse() function provided by jQuery. In the following example date '1-1-2000' will be static. Because this function is only for compare the times. Thanks.

<script type="text/javascript">
   $(document).ready(function () {
       $('#chk').click(function () {
           var st = $('#startTime').val();
           var et = $('#endTime').val();
           if (Date.parse("1-1-2000 " + st) > Date.parse("1-1-2000 " + et)) {
               return false;
           }
           else {
               return true;
           }
       });
   });

</script>

No comments:

Post a Comment