Solved

compare dates

Posted on 2004-10-03
7
186 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
  • 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now