954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

enter a valid date

No one seemed to help me out with my other question :sad: so was wondering if you can help me with this one. I want to validate a date so that the user is only allowed to enter a correct date. I have no idea how I could do it and would appreciate if someone showed me some coding of how I can do it. I want the date to be in this format:

write(' Date Out (dd/mm/yyyy format)....');
readln(rr.date_out);
writeln;
write(' Date In (dd/mm/yyyy format)....');
readln(rr.date_in);

thanks :eek:

exotic_ang
Newbie Poster
20 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

I'm not a pascal prpgrammer so I can't write the program for you, but it will be the same in any language.

First create three string objects called month, day and year then use substring (or something similar) that will extract the appropriate digits from the original string into each of the three objects. Next convert each of the three sub strings into integers. Finally check that the month is between 1 and 12, the day is between 1 and last day of the month.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

thanks for the help but I kind of figured that out already! The probelm im finding is in coding it. thanks just the same

exotic_ang
Newbie Poster
20 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
thanks for the help but I kind of figured that out already! The probelm im finding is in coding it. thanks just the same

you must post your code -- no one can help you if you do not.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

what do I NEED TO POST? i THINK THERES NOTHING I CAN PASTE SINCE I CANT GET TO IT THE ONOLY THINK I MANAGED TO WRITE IS THE BIT I PASTED IN THE FIRST MESSAGE

exotic_ang
Newbie Poster
20 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

>>what do I NEED TO POST?
well, what have you tried? you already said you figured out what you need to do -- thats a good start. Now try putting that down on paper, schetch out on paper what you need to accomplish. Not code at this point, but just ideas. Don't get overwhelmed with the assignment -- take it one small step at a time.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

ok i managed to arrive here...I modified everything and made the date automatically. Now when the date is stored, it is only stroed in numbers example instead of Monday, 11/7/2007 it stroes as 11172007 . How can I make it store the date as it is dispayed? here is the code i did :

GetDate(year,month,day,dayofweek);
writeln(' Date Out.....', days[dayofweek],', ',month:0, '/', day:0, '/', year:0);
rr.date_out := WORDTOSTR(dayofweek)+WORDTOSTR(month)+WORDTOSTR(day)+WORDTOSTR(year);

by the way, WORTOSTR is a procedure I made to convert from word to string.

exotic_ang
Newbie Poster
20 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

Does TDate not provide the functionality you require?

pty
Posting Pro
530 posts since Oct 2005
Reputation Points: 64
Solved Threads: 39
 
radu84
Junior Poster
171 posts since Dec 2006
Reputation Points: 14
Solved Threads: 16
 

I think he means if the user enters a date and if it's in the wrong format, then the program tells the user that.

Correct me if I'm wrong.

linux
Posting Shark
933 posts since Aug 2006
Reputation Points: 118
Solved Threads: 30
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You