Solved

Compare two date / times...

Posted on 2004-09-15
8
201 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

860 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