473,222 Members | 1,815 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,222 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 7057
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. ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.