• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Lenin Chada
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(DateFormat.java:324)
at Sample.StringCompare1.compare(Sample.java:121)
at java.util.Arrays.mergeSort(Arrays.java:1181)
at java.util.Arrays.mergeSort(Arrays.java:1188)
at java.util.Arrays.sort(Arrays.java:1128)
at Sample.Sample.main(Sample.java:75)
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
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new SimpleDateFormat("dd-mon-yy");

"dd-mon-yy" is not a valid format specifier. Check out the JavaDoc for SimpleDateFormat for legal formatting.
hth,
bear
 
Lenin Chada
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you that solved my problem
new SimpleDateFormat("dd-MMM-yy")
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and thank you for sharing with us what you learned.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic