Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compare 2 Dates in String Format

 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi buddies
My target is to compare two dates, which are in String format. The Possible String formats are
"10-OCT-2002" and "10-10-2002".
Please guide me which class should i use, in order to get the my string converted to date,
AND
Which functions should i use, So that i can compare (less than, greater than comparision) two dates (converted above with the help of some xyz class)
Please guide me at your earliest....

Regards
Manish
[ August 27, 2002: Message edited by: Manish Sachdev ]
[ August 28, 2002: Message edited by: Manish Sachdev ]
[ August 28, 2002: Message edited by: Manish Sachdev ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at http://jinx.swiki.net/223 (and don't hesitate to augment it - it's editable for everyone).
 
Jonathan Roberts
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about
SimpleDateFormat formatter = new SimpleDateFormat ("[yy.MM.dd hh:mm:ss:SSS zz]");
Date currentTime_1 = new Date();
String date = formatter.format(currentTime_1);
Have a look at the SimpleDateFormat on how to format the date time differently.
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jonathan and Ilja for the effort taken by you to help me out,
But the information provided by you is not helping me completely,
Can you please provide me the code for the task, which i need to acheive.
1)I have two dates :
"10-JAN-1920" and "10-APR-1950",
2) Please provide me the code to convert the above dates to String and After conversion, compare the above two dates which can tell me that the first date is greater than the second one.....
I hope, that you understand the problem i am facing......
I want both the above things to be accomplished

Waiting for a solution...
[ August 28, 2002: Message edited by: Manish Sachdev ]
[ August 28, 2002: Message edited by: Manish Sachdev ]
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jamie,
Thanks for the efforts that you have taken to help me out. This was the exact thing which i needed.......
Thank you very Much....
Regards
Manish
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic