RE: [PHP] dates only in the future
| From: | Boget, Chris | Date: | Tue, 25 Sep 2001 16:34:00 +0000 |
| Subject: | RE: [PHP] dates only in the future | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-68726@lists.php.net to get a copy of this message | ||
> I'm looking for a function which enables me to allow user
> only to enter those dates which are still to come. In my head
> I have three <select> things... one for day, one for month and
> one for year. In order to prevent the user from submitting the
> form with the date which is in past, I need probably Javascript.
> Am I correct?
Only if you want to check before the form gets submitted...
> I rather prefer to keep my site Javascript free and therefore it
> would be great if somebody has already written such a function
> and would be ready to share it with me/others. If not, any ideas
> how to start... ????
Here is a function I use. Call after the form is submitted.
function verifyDate( $date_month, $date_day, $date_year, $notprior = "" ) {
// v. 1.1
// 1999.11.19 - to check to make sure that the selected dates are
// within the appropriate range:
// ie. days cannot exceed 31, months cannot exceed 12 and
// years cannot be more than 10 years in the future.
$retval = 1;
$today = MkTime(0,0,0, date( "m" ), date( "d" ), date( "Y"
));
$selected_date = MkTime(0,0,0, $date_month, $date_day, $date_year);
if(( $date_month > 12 ) ||
( $date_day > 31 ) ||
(( $date_year < ( date( "Y" ) - 95 )) || ( $date_year > date( "Y"
))))
{
$dategood = 0;
} else {
$dategood = checkdate( $date_month, $date_day, $date_year );
}
if( !$dategood ) {
$retval = "Date is invalid. Please make sure that the day selected is
valid for the month selected<br>\n";
} elseif (( $today > $selected_date ) && ( $notprior )) {
$retval = "Date Selected Is Prior To Today<br>\n";
}
return $retval;
} // End function verifyDate();
Chris