473,563 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparision between Date strings.

157 New Member
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 4266
sicarie
4,677 Recognized Expert Moderator Specialist
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 'GregorianCalen dar' 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 Recognized Expert Moderator Specialist
You can change them into date objects, or 'GregorianCalen dar' 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 MVP
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(St ring date) which requires date in the format YYYY-MM-DD, then you can use the Date methods or set it as time to a GregorianCalend ar 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
42986
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 mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our...
3
1630
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 if/select case, etc; after performing the case-insenisitive compare, the indicator can be reset to allow the conventional comparision of strings? kd
2
3554
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
1666
by: melissa.nava | last post by:
Here is my code: ***** Public Property DOB() As Date Get Try DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear)
20
35425
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 project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using. Thanks for any response
1
4579
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 < today) alert("date1 is less than today);
1
1736
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
2846
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 result. On tracing the program i noticed that the strings "s" and "t" get modified somehow in the comp function and as a result i am getting...
1
1295
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 the date,,, so pls tell me any one thank you,
0
7580
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.