-5

I have time in the format "hh:mm" in 24 hr format. Now how to compare two times such that it returns the boolean value . And if both the times is same in hours then should compare minutes and return either true or false. Meaning t1="15:30" and t2="15:40" should return false if checking whether t1> t2 using javascript

user13763
  • 83
  • 7

2 Answers2

0
return t1==t2

is enough for the above question

Vikram Jakkampudi
  • 502
  • 1
  • 3
  • 16
0

Dates that are formatted HH:mm (ie always 2 digit hours) with 24 hours time will compare correctly as strings without converting them;

var t1 = "15:30";
var t2 = "15:40";

console.log(t1 < t2);
console.log(t1 == t2);
console.log(t1 > t2);

> true
> false
> false
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294