• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your variable is probably considered as a string.
Use the eval function to convert it to an integer.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
parseInt is better than eval.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic