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

x
Solved

# Compare two date / times...

Posted on 2004-09-15
Medium Priority
207 Views
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.
0
Question by:greedy1
[X]
###### 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
• 4
• 3

LVL 86

Accepted Solution

CEHJ earned 200 total points
ID: 12064020
boolean late = date1.after(date2);
0

LVL 86

Expert Comment

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

LVL 37

Expert Comment

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

boolean late = a.after(b);
0

LVL 37

Expert Comment

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

LVL 37

Assisted Solution

zzynx earned 100 total points
ID: 12064103
Like

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss");
Date a, b;
try {
a = sdf.parse(yourString1);
b = sdf.parse(yourString2);
} catch (ParseException ex) {
}
0

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.
0

LVL 86

Expert Comment

ID: 12064307
8-)
0

LVL 37

Expert Comment

ID: 12064359
>> You guys have officially made me LAZY
:Â°D

>> 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
0

## Featured Post

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â€¦
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
Course of the Month4 days, 21 hours left to enroll