aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Problem in Comparing Values; 7>14 returns true???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem in Comparing Values; 7>14 returns true????" Watch "Problem in Comparing Values; 7>14 returns true????" New topic
Author

Problem in Comparing Values; 7>14 returns true????

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi all
In my web application i am allowing the user to enter from date/Time and
To date/Time in the below format. MM/DD/YYYY mm:HH:ss
i am acheiving above functionality, using some Javascript (Datepicker.js)that already exists.

I wrote the function my self to compare the From and to date and validating the From date to be less than to date.

I am comparing the date by splitting the above format to different pieces using split functions. The problem i am facing is when i compare my from date with to date it returns some bizzare results

from date 7; to date 14
7>14 returns true;

from date 17; to date 21
17>21 returns false;

i am getting problem whenever i am comparing the single digit with two digit
say 8>12 ; 3>12; .
I thought the problem might be due to some extra spaces but that not so.
i checked the length it returns 1;

i donno wheres the problem is ?

Any pointers will greatly appreciated.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Your variable is probably considered as a string.
Use the eval function to convert it to an integer.


[My Blog]
All roads lead to JavaRanch
Jon Hanlon
Greenhorn

Joined: May 02, 2006
Posts: 8
parseInt is better than eval.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

parseInt is better than eval.

Telling me why it is better is even better
Please explain. (I'm a Javascript novice)
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Can I ask why are you ripping apart the Date to compare it to I assume another date.

You can just do



Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Comparing Values; 7>14 returns true????