473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Comparision between Date strings.

157 100+
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
3 4236
sicarie
4,677 Expert Mod 4TB
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
4,677 Expert Mod 4TB
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
r035198x
13,262 8TB
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

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

Similar topics

15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
3
by: kd | last post by:
Hi All, How to perform case-insensitive comparision of strings? Would there be some kind of an indicator, which when set to true, would allow case-insenitive comparision of strings using...
2
by: Bernd Hohmann | last post by:
Dear collegues, small query problem. A table (simplified example)... customer as char(5) inv_date as date amount as double
10
by: melissa.nava | last post by:
Here is my code: ***** Public Property DOB() As Date Get Try DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear)
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
1
by: viswanadhds | last post by:
Hi all, I was trying to compare a date with todays date like this var date1 = getDateObject(document.groupForm.endDate.value); var today = new Date(); today.setHours(0,0,0); if(date1 <...
1
by: srikanthch3 | last post by:
Hi I had problem in comparision of the start date and end date vba in excell.if u give the end date 2/2/07 and start date 3/2/07, it is accepting.so any one can help. Srikanth
35
by: user34 | last post by:
(Sorry if this gets posted twice) Hi all. I am trying to learn C.As a simple exercise i tried to write a code which would compare two strings using pointers. However i am not getting the correct...
1
kaleeswaran
by: kaleeswaran | last post by:
hi! i am doing airways project...so i need to compare my date with my current date and user entry date...so i can format my date by using SimpleDateFormat.but i could not find out how to compare...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.