wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to compare 2 Dates in String Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to compare 2 Dates in String Format" Watch "How to compare 2 Dates in String Format" New topic
Author

How to compare 2 Dates in String Format

M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
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 ]

Regards, Manish
SCJP 1.4
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Take a look at http://jinx.swiki.net/223 (and don't hesitate to augment it - it's editable for everyone).


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jonathan Roberts
Greenhorn

Joined: Aug 23, 2002
Posts: 4
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

Joined: Dec 13, 2001
Posts: 106
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

Joined: Jul 09, 2001
Posts: 1879


M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to compare 2 Dates in String Format