compare dates

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
{
/////
}
wallpaperpasteAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
... and of course

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

should be

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
0
 
CEHJCommented:
SimpleDateFOrmat sdf = new SimpleDateFormat("dd-MM-yy");
Date d1 = sdf.parse(date1);
Date d2 = sdf.parse(date2);
boolean earlier = if d1.before(d2);
0
 
CEHJCommented:
>>boolean earlier = if d1.before(d2);

should have been

boolean earlier = d1.before(d2);
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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

Will this work?
0
 
CEHJCommented:
Yes (if you apply my correction ;-)) Or simpler:

if (earlier) {
   // do it
}
0
 
OsdNACommented:
:)
Thanks
0
 
CEHJCommented:
8-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.