What is wrong with this simple if

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

What is wrong with this simple if

Post by klevis miho »

Why this code becomes true?

timenow = '14:57';
if((timenow >= '0:00') && (timenow < '6:00')) {
alert('true');
}
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: What is wrong with this simple if

Post by VladSun »

Because you're comparing strings (alphabetically), not numbers.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: What is wrong with this simple if

Post by McInfo »

Use zero placeholders, as in '00:00' and '06:00'.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: What is wrong with this simple if

Post by klevis miho »

But how to compare hours?
Post Reply