neoHOW7: Check if a date is valid


Following up on Check if a particular year is a LEAP year, here is a routine to check if a date is valid. By definition, a date is valid if all of theese conditions are true ...

a) The year is an integer greater than or equal to 0
b) The month is an integer between 1 and 12
c) For months 1, 3, 5, 7, 8, 10 and 12, the day is an integer between 1 and 31
d) For months 4, 6, 9 and 11, the day is an integer between 1 and 30
e) For month 2, the day is an integer between 1 and 29 (Leap Years) or 28 (otherwise)

You deploy this subroutine (IsThisAValidDate) by supplying the value to be checked in variable [IsThisAValidDate/Input] ... and upon return, examine the contents of [IsThisAValidDate/Answer] ... the contents of which will be "True" or a description of the error encountered.

Here is an example code snippet ...



And here is the subroutine you would paste in your pub's SubRoutines section ...



Of course, if you plan on using such a function in many projects, you might consider turning the subroutine into a NeoBook Function ... something you might Call from any pub in your computer ... for example ...

Back