?
Solved

compare dates

Posted on 2004-10-03
7
Medium Priority
?
195 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

764 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