Adam Confino wrote:
So the concept is that you would take two strings (one would be user input, one is data in the model\database), convert them to dates using SimpleDateFormat, and then comparing the date objects to each other??
That is probably how I would go about it. The key is you need to compare apples to apples. So you either need to compare a Date to a Date or a String to a String. Since you are woking with Dates, it makes sense to use Date objects, not Strings. This gives you all the abilities that the Date class brings to you. If you used Strings, you can't determine that 2009-09-04 is equal to 04-SEP-2009. But if you convert those Strings to Date objects, you can now compare them. (You would need two different
SimpeDateFormat objects to convert the two different Strings to dates.)
One thing to keep in mind is that a Date object is really a DateAndTime object. In other words, it not only stores the date, but the time to millisecond precision. So if I do this:
Even though they will have the same date, the objects are not equal since they will have different times. The key point there is that if you truly only care about the Date, and not the time, you need to create your Date objects in such a way that the times are set the same, typically to midnight when you only care about the date. Using the SimpleDateFormat can accomplish this. Here's a little example program that can get you started in understanding and comparing dates:
Play around with that and let us know if you have any more questions.
And welcome to JavaRanch.