Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

compare dates

Posted on 2004-10-03
7
Medium Priority
?
197 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 400 total points
ID: 12211465
... and of course

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

should be

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

610 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