Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6118353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:25:36+00:00 2026-05-23T15:25:36+00:00

I have two time strings in hh:mm:ss format. (eg: 12:40:13 and 20:01:01 .) How

  • 0

I have two time strings in hh:mm:ss format. (eg: 12:40:13 and 20:01:01.) How can I compare these in JavaScript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:25:36+00:00Added an answer on May 23, 2026 at 3:25 pm

    DEMO HERE

    I prefer to have date objects, but as pointed out elsewhere, you can just convert to seconds if you want to do simple compares

    function dateCompare(time1,time2) {
      var t1 = new Date();
      var parts = time1.split(":");
      t1.setHours(parts[0],parts[1],parts[2],0);
      var t2 = new Date();
      parts = time2.split(":");
      t2.setHours(parts[0],parts[1],parts[2],0);
    
      // returns 1 if greater, -1 if less and 0 if the same
      if (t1.getTime()>t2.getTime()) return 1;
      if (t1.getTime()<t2.getTime()) return -1;
      return 0;
    }
    
    alert(dateCompare("12:40:13","20:01:01"));
    

    For seconds:

    function dateDiff(time1,time2) {
      var t1 = new Date();
      var parts = time1.split(":");
      t1.setHours(parts[0],parts[1],parts[2],0);
      var t2 = new Date();
      parts = time2.split(":");
      t2.setHours(parts[0],parts[1],parts[2],0);
    
      return parseInt(Math.abs(t1.getTime()-t2.getTime())/1000);
    }
    

    Assuming you have 24 hour times and same padding you can do simple string compare

     var t1 = "12:40:13", t2= "20:01:01";
     if (t1<t2) {
        console.log(t1," is < ", t2);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two time strings in HH:MM:SS format. For example, str1 contains 10:20:45 ,
I have two arrays with time values in them in this format. 00:00:00 which
I have two select fields in a form. Every time one of these select
Greetings, I have file with the following strings: string.Format({0},{1}, Having \Two\ On The Same
I have two strings from an android application in ISO 8601 format that I
I have two time picker jquery controls that have time in the format of
I have a text file that contains date, and two time-strings separated by spaces
I have two controls whos code are run time rendered as below: ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_gdvItinerary_ctl03_txtTravelDate ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_gdvItinerary_ctl04_txtTravelDate
I have two variables: char charTime[] = TIME; char buf[] = SOMETHINGELSE; I want
I have two information and want them to be displayed at the same time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.