0

I have two times start time and end time. The code is running properly but when the start time is 10:55 AM and end time is 10:00 PM then it takes start time greater than end time . but it should not. How to resolve the issue.Thanks is advance.

 function checktime() {
    var start = document.getElementById("StartTime").value;//10:55AM
    var end = document.getElementById("EndTime").value;//10:00PM

        if (start > end) {
            alert("End time should exceed the start time");
        }         
        return false;
    }
Demon
  • 11
  • 1
  • 4
  • 1
    Please, add the html to your question and create a snippet, then we can deeply understand what is you problem! – reisdev Jan 29 '20 at 13:05
  • I think you have not done enough research on this issue, seems like you will be down voted – Akhil Aravind Jan 29 '20 at 13:08
  • The values start and end are text. You need to make them into date-times to carry out a valid comparison. Do some research on the javascript date() constructor. – Vanquished Wombat Jan 29 '20 at 13:09

1 Answers1

0

Why don't you convert it in 24h format in your code? In my opinion it will be much simplier. Or you can add special character/value/variable for identify if time is AM or PM. Or do some Date parsing to convert your text to usable time viariable

Sahasrar
  • 33
  • 5
  • same issue will remain because 10:55 is again greater than 10:00. – Demon Jan 29 '20 at 13:20
  • I don't know exacly what you writing to variables and format of those. Because if your html code is just input for string and you will put there characters like (/:-") you can't compare it's values. You should check date() function. Or filter your inputs to only number. – Sahasrar Jan 29 '20 at 13:34