Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
I have to validate that is end time greater then start time using jquery

I have to validate that is end time greater then start time. and my time formate 'HH:MM' ,24 hour formate

eg. start time = 09:14 and end time 12:15 - valid

and start time = 09:14 and end time 01:15 - not valid

thanks have a nice day

I think a/c to this time it should be validate.i am little confused why are giving me this error end time should be greater then start time.

enter image description here

jquery

 $(document).change(function(){

  var startTime =$('#start_time').val(); // 9:15 Am
  var endTime = $('#end_time').val();    // 1:00 pm

    var startTimeParts = startTime.split(":");
    var endTimeParts = endTime.split(":");

    var startDate = new Date();
    startDate.setHours(startTimeParts[0],startTimeParts[1],0,0);
    var endDate = new Date();
    endDate.setHours(endTimeParts[0],endTimeParts[1],0,0);
    if(endTime != ""){
      if (startDate < endDate){
        $(".endTimeMessage").hide();
        $('#btnSubmit').removeAttr("disabled",true);
        return true;
    }else{
        $(".endTimeMessage").show();
        $(".endTimeMessage").text("End time should be greater then start time");
        $('#btnSubmit').prop('disabled', true);
        return false;
    }
    }

});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use setHours function to set the time and then compare the values.

eg.

    $(document).change(function(){
        var startTime = "09:14";
        var endTime  =   "01:00";

        var startTimeParts = startTime.split(":");
        var endTimeParts = endTime.split(":");

        var startDate = new Date();
        startDate.setHours(startTimeParts[0],startTimeParts[1],0,0);
        var endDate = new Date();
        endDate.setHours(endTimeParts[0],endTimeParts[1],0,0);

        if (startDate > endDate){
            $(".endTimeMessage").hide();
            $(".endTimeMessage").text("End time should be greater then start time");
            $('#btnSubmit').removeAttr("disabled",true);
            return true;
        }else{
            $(".endTimeMessage").show();
            $(".endTimeMessage").text("End time should be greater then start time");
            $('#btnSubmit').prop('disabled', true);
            return false;
        }
    });

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!