Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your variable is probably considered as a string.
Use the eval function to convert it to an integer.
 
Jon Hanlon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parseInt is better than eval.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I ask why are you ripping apart the Date to compare it to I assume another date.

You can just do



Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic