By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

Comparision between Date strings.

100+
P: 157
I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings?

Eg:

String Entered Date: "28-02-2007"
String Backend Date: "20-01-2006"

I need to have some function which tells me that the entered date is 1 year 1 month and 08 days ahead of the backend date.

Right now I am using StringTokenizer(EnteredDate,"-") and StringTokenizer(BackendDate,"-") to split these two strings and get their day, month, year stored in seperate variables and then I carry out the comparision between them in if-conditions. But is there any other way to directly compare these dates?
Feb 28 '07 #1
Share this Question
Share on Google+
3 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings?

Eg:

String Entered Date: "28-02-2007"
String Backend Date: "20-01-2006"

I need to have some function which tells me that the entered date is 1 year 1 month and 08 days ahead of the backend date.

Right now I am using StringTokenizer(EnteredDate,"-") and StringTokenizer(BackendDate,"-") to split these two strings and get their day, month, year stored in seperate variables and then I carry out the comparision between them in if-conditions. But is there any other way to directly compare these dates?
You can change them into date objects, or 'GregorianCalendar' objects, and use parseDate to set your format. Check the javadocs for the date class, it should help.
Feb 28 '07 #2

sicarie
Expert Mod 2.5K+
P: 4,677
You can change them into date objects, or 'GregorianCalendar' objects, and use parseDate to set your format. Check the javadocs for the date class, it should help.
Sorry - parseDate to GET the date, I think its dateFormat to set the ... well ... format.
Feb 28 '07 #3

10K+
P: 13,264
I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings?

Eg:

String Entered Date: "28-02-2007"
String Backend Date: "20-01-2006"

I need to have some function which tells me that the entered date is 1 year 1 month and 08 days ahead of the backend date.

Right now I am using StringTokenizer(EnteredDate,"-") and StringTokenizer(BackendDate,"-") to split these two strings and get their day, month, year stored in seperate variables and then I carry out the comparision between them in if-conditions. But is there any other way to directly compare these dates?
Can create a Date object using Date.valueOf(String date) which requires date in the format YYYY-MM-DD, then you can use the Date methods or set it as time to a GregorianCalendar object and use the methods there.
Mar 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.