Compare two date / times...

Posted on 2004-09-15
Last Modified: 2010-05-18
I want to evaluate whether date/time a > date/time b.

For example, I pass in 2004-09-15-13.00.00(variable a), if that is greater than (Later than) 2004-09-15-08.00.00(variable b) then I need to flag it as "late".

The dates could be different days as well....not just times.
Question by:greedy1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 86

Accepted Solution

CEHJ earned 50 total points
ID: 12064020
boolean late = date1.after(date2);
LVL 86

Expert Comment

ID: 12064034
If you've got them as Strings, use SimpleDateFormat, like i showed you in your last question
LVL 37

Expert Comment

ID: 12064045
if a and b are Date's:

boolean late = a.after(b);
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 37

Expert Comment

ID: 12064066
>> If you've got them as Strings, use SimpleDateFormat
indeed :)
LVL 37

Assisted Solution

zzynx earned 25 total points
ID: 12064103

SimpleDateFormat sdf = new SimpleDateFormat("");
Date a, b;
try {
        a = sdf.parse(yourString1);
        b = sdf.parse(yourString2);
} catch (ParseException ex) {

Author Comment

ID: 12064255
You guys have officially made me LAZY.  I briefly scanned Date javadoc, skipped over 'after()' obviously and thought I'll just go ask on EE it's easier than looking....LAZY : )

CEHJ beat you to it zzynx, but thanks for the effort , I'll increase the points and give you some too.
LVL 86

Expert Comment

ID: 12064307
LVL 37

Expert Comment

ID: 12064359
>> You guys have officially made me LAZY

>> CEHJ beat you to it zzynx,
Yeah, with one minute. The guy's like lightening ;°)

>> but thanks for the effort , I'll increase the points and give you some too.
much appreciated, mate. Thanks

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql import cannot be resolved jsp 3 117
jmss example java 2 48
java imports not found 4 71
Setup Eclipse for Andriod development 2 20
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question