Solved

compare dates

Posted on 2004-10-03
7
191 Views
Last Modified: 2011-09-20
Hi, How can I check if a certain date occurs before another:
string date1 = "22-12-01";
string date2 = "22-12-02";
if(date1 < date2) //date1 occurs before date2
{
/////
}
0
Comment
Question by:wallpaperpaste
[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
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12211446
SimpleDateFOrmat sdf = new SimpleDateFormat("dd-MM-yy");
Date d1 = sdf.parse(date1);
Date d2 = sdf.parse(date2);
boolean earlier = if d1.before(d2);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12211448
>>boolean earlier = if d1.before(d2);

should have been

boolean earlier = d1.before(d2);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 12211465
... and of course

>>SimpleDateFOrmat sdf = new SimpleDateFormat("dd-MM-yy");

should be

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Expert Comment

by:OsdNA
ID: 12211497
Thanks for your comments.
>>boolean earlier = if d1.before(d2);
if(earlier == true)
{
}

Will this work?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12211512
Yes (if you apply my correction ;-)) Or simpler:

if (earlier) {
   // do it
}
0
 

Expert Comment

by:OsdNA
ID: 12211727
:)
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12211903
8-)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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 This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
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

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