Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Compare two date / times...

Posted on 2004-09-15
Medium Priority
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 200 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);
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

LVL 37

Expert Comment

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

Assisted Solution

zzynx earned 100 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

670 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