Hello,
I need a way to verify a user-entered date. I briefly worked with timelocal(), but discovered that it quite happily returns a value for Feb. 31st. It's parameter checking is quite primative.
Is there a 'clean' way to do this?
-with thanks,
Mike
Well, I put on my programmer's hat and came up with something!
My function looks like: &dateValid($mon, $day, $year) where mon is 1..12, day is 1..31, and year is 1970..2100. It returns the logical value TRUE or FALSE.
Comments are welcome, particularily if I've got a logic BUG in this baby! -thanks.
use Time::Local;
sub dateValid {
my ($mm, $dd, $yy) = @_;
my ($FALSE) = 0;
my (@t);
Hi, If you load the Date::Calc module you can use the check_date function.
if (check_date($year,$month,$day))
This function returns "true" ("1" if the given three
numerical values "$year", "$month" and "$day" constitute a valid date, and "false" ("0" otherwise.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.