How can I compare two time strings in the format HH:MM:SS?

As Felix Kling said in the comments, provided your times are based on a 24 hour clock (and they should be if there’s no AM/PM) and provided they are always in the format HH:MM:SS you can do a direct string comparison:

var str1 = "10:20:45",
    str2 = "05:10:10";

if (str1 > str2)
    alert("Time 1 is later than time 2");
else
    alert("Time 2 is later than time 1");

Leave a Comment