• 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

Java Script

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
want to compare two dates..
one is online date and another is offline date
all i want is offline date greater than online date
simply lost how to do it..
can do lot of java but when comes to javascript.
"Who is john Galt.."any way..would really really appriciate if somebody can help
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fret ye not! It's as simple as:

Jules

P.S. This should really be on the HTML/JavaScript forum
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually it is better to use make sure that boh dates are in a date object and then compare it. This will make sure that the two dates are in the correct format when they are compared.

For example:


You then can use it like this



Eric
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

So how does that work in practice then? What mechanism is used to determine if Object1 is greater than Object2?

In my example offlineDate and onlineDate are supposed to be Date objects, though I didn't make that explicitly clear. I didn't realise that you can compare them without the valueOf(). Is it implicit?

Jules
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not need to use valueOf(), it compares the two objects without any errors. If you subtract two date objects, it returns a result in milliseconds.

JavaScript is not as picky as other lanuages, you can compare the date object with out any problems.

Eric
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool!

Jules
reply
    Bookmark Topic Watch Topic
  • New Topic