Solved

Compare two date / times...

Posted on 2004-09-15
8
199 Views
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.
0
Comment
Question by:greedy1
  • 4
  • 3
8 Comments
 
LVL 86

Accepted Solution

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

Expert Comment

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

Expert Comment

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

boolean late = a.after(b);
0
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 
LVL 37

Expert Comment

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

Assisted Solution

by:zzynx
zzynx earned 25 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

by:greedy1
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

by:CEHJ
ID: 12064307
8-)
0
 
LVL 37

Expert Comment

by:zzynx
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

Gigs: Get Your Project Delivered by an Expert

Select from 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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

786 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