Page 1 of 1
What is wrong with this simple if
Posted: Mon Sep 20, 2010 7:58 am
by klevis miho
Why this code becomes true?
timenow = '14:57';
if((timenow >= '0:00') && (timenow < '6:00')) {
alert('true');
}
Re: What is wrong with this simple if
Posted: Mon Sep 20, 2010 2:15 pm
by VladSun
Because you're comparing strings (alphabetically), not numbers.
Re: What is wrong with this simple if
Posted: Mon Sep 20, 2010 2:26 pm
by McInfo
Use zero placeholders, as in '00:00' and '06:00'.
Re: What is wrong with this simple if
Posted: Mon Sep 20, 2010 3:27 pm
by klevis miho
But how to compare hours?