File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Comparing dates.....Help.....Please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing dates.....Help.....Please " Watch "Comparing dates.....Help.....Please " New topic

Comparing dates.....Help.....Please

Lenin Chada

Joined: Mar 10, 2003
Posts: 3
Iam trying to compare two dates i am getting the following error, can anybody please help me
java.text.ParseException: Unparseable date: "21-DEC-03"
at java.text.DateFormat.parse(
at java.util.Arrays.mergeSort(
at java.util.Arrays.mergeSort(
at java.util.Arrays.sort(
at Sample.Sample.main(
here is my code
SimpleDateFormat sdf = new SimpleDateFormat("dd-mon-yy");
Date d1 = sdf.parse(r1[column]);
Date d2 = sdf.parse(r2[column]);
int result = d1.compareTo(d2);
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61103

new SimpleDateFormat("dd-mon-yy");

"dd-mon-yy" is not a valid format specifier. Check out the JavaDoc for SimpleDateFormat for legal formatting.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lenin Chada

Joined: Mar 10, 2003
Posts: 3
thank you that solved my problem
new SimpleDateFormat("dd-MMM-yy")
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
...and thank you for sharing with us what you learned.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
It is sorta covered in the JavaRanch Style Guide.
subject: Comparing dates.....Help.....Please