473,407 Members | 2,359 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,407 software developers and data experts.

How to compare the date format?

1
I am writing a programe in which user is asked to enter his/her date of birth in DD/MM/YYYY format. What if he/she enters the date in other format? How can I write a syntax to check whether he/she enters the date in the given format? Can somebody give me an exact idea?
Thanks
Jul 8 '06 #1
6 7061
Banfa
9,065 Expert Mod 8TB
You check that the / are in the correct place in the string and you check that all the values entered are sensible, i.e. MM is in range 1 - 12 and DD is in correct range given MM.

You will never be able to completely verify a date entered in this format, for instance is someone accidentally enters 6th March 2006 in american format (MM/DD/YYYY) or 03/06/2006 there is no way your program can know this, it will just treat it as 3rd June 2006. Put up a prompt telling the user what format to use.
Jul 10 '06 #2
I am writing a programe in which user is asked to enter his/her date of birth in DD/MM/YYYY format. What if he/she enters the date in other format? How can I write a syntax to check whether he/she enters the date in the given format? Can somebody give me an exact idea?
Thanks
You write the program which doesn't receive the date at a single stretch, that is first you prompt the user to enter DD, if he enters that then prompt him to enter MM and after that prompt him to enter YYYY.
Example :
Enter the Day =
if he enters the above value, then prompt him for
Enter the month =
and then
Enter the year =
Collect all the value in whichever format you want and thus the above problem will be solved.
Jul 12 '06 #3
I agree with Ashish_CPP in that if the input is forced the right way much of the problem is solved. For example If you give an html field for instance with labels DD<field> , MM<field>, YYYY<field> and they put the wrong days into the wrong fields that's their mistake. You don't know what their date is ahead of time. I think your question relates to them entering DD-MM-YYYY instead of the / ? if so you can search some regular expresions for this you might be able to solve SOME cases but not all.
Jul 12 '06 #4
Banfa
9,065 Expert Mod 8TB
If you are going complicate things by asking for separate fields then you may as well go the who hog and complicate things by getting the user to input the month as text or a text abrieviation (November or Nov).

If you are using a GUI this works well because you can use drop down lists to contain the data so you have control of the strings in use as well.

Once the month is a name not a number the date is unambiguous.
Jul 12 '06 #5
I think even if you are not using GUI application, the logic that I gave in my previous reply will work fine, the advantage is that the you can collect the user input in an array and then print wherever and in whichever format you want. you can even change the format at run time. isn't it ?
Jul 12 '06 #6
Banfa
9,065 Expert Mod 8TB
I think even if you are not using GUI application, the logic that I gave in my previous reply will work fine, the advantage is that the you can collect the user input in an array and then print wherever and in whichever format you want. you can even change the format at run time. isn't it ?
Yes :D :p :)
Jul 12 '06 #7

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

Similar topics

1
by: WroteForLuck | last post by:
I am trying to write a simple SQL statement which will take a string (startdate) in the format DDMMYYYY and compare it to a date stored in an Oracle database. My SQL is as follows: <% "select...
4
by: alexis | last post by:
Hi, In a form I have the curent date <input name="datetoday" type="hidden" value="<? echo date("d/m/Y"); ?>"> and <input type=text name="datebox" size=15> The date format is d/m/Y...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
9
by: Rich | last post by:
Thanks for the Help in my previous post. I've been working on this and it's almost what I want. I want to obtain the user's current age by comparing their date of birth (user inputs) to the...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
3
by: Peter | last post by:
ASP.NET 1.1, this is a Intranet application and runs only on IE. I have two webform text boxes which contain dates - starting date and ending date. The dates could be in any format. for...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
0
by: Mike P | last post by:
What date format does the Compare Validator check against? The date format of the web server or of the client? <asp:CompareValidator ID="CompareValidator2" runat="server" Display="None"...
1
by: vrparekh | last post by:
in my webapplication,user pick date in dd/mm/yy format, and i want to compare that date with another date using compare validator but compare validator compare the dates using mm/dd/yy format. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.