Question validate a simple date?

cozmo

Member
Joined
Sep 28, 2012
Messages
7
Programming Experience
3-5
Hello All,

I have to validate a simple date field ==> [ 12/12/12 ] Without using ANY built-in date routines or functions in VB.

that's it. When I first approached this I actually chuckled and thought, "that's it?" Well, I'm not laughing now... :-( I thought this would be just a bunch of IF statements but no, it seems more than that.

So... I actually have no clue where to start at this point and wouldn't mind some starting points or suggestions.

Thank you.

-Coz
 
Define validate, and also define date field. Is it an actual DateTime, or a string? And what do you need to validate?

I still don't understand why teachers insist on using absolutely ludicrous examples for exercises like that... All it will teach you is how to do it the wrong way. I can think of much better real-world exercises.
 
Hi,

I think it's more about string manipulation and conditional statements that are at work here other than date checking on the basis that no date functions can be used.

So here goes:-

1) If this is a true date type variable than first create and convert to a string variable
2) Create three integer variables and then use string manipulation routines to figure out the day, month and year
3) Then use conditional statements to determine if the day, month and year are valid.

Things to consider are:-
Different number of days in different months
Leap years, different number of days in February

Note, your routine should be able to validate every example date presented to it and not just the sample provided.

Good luck.

Cheers,

Ian
 
If you want to impress your teacher do it with RegEx... :)

I have been thinking about a regular expression as I've used them in Perl and shell scripts but I'm not sure how I would implement one in this application? I've only used regex to validate a pattern "##/##/##" but certainly not to check if a "date" is valid and do so from a string since we're not permitted to use VB's date functions. My extent of programming *anything* has been limited to editing others' scripts, Javascript and HTML. I don't think that I've ever attempted anything this granular since we have pre-built objects and modules that handle so many things now. But now that you mention it, I'm going to re-assess regex and see if I can make it work there.

Good suggestion though. THanks!
 
Back
Top