开发者

PHP birth checker error

I currently have a registration form which checks a persons date of birth via three inputs

day(dd) - month(mm) - year(yyyy)

The code I am using to check:

    function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[0], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[0], $date_parts2[2]);
return $end_date - $start_date;
}
//Enter date of birth below in MM/DD/YYYY
$dob="$day/$month/$year";
$dob2 = "$dob";
$one =  round(dateDiff("/", date("d/m/Y", time()), $dob2)/365, 0) . " years.";
if($one <13){
?>
You must be 13 years of age or older to join!
<?
}else{
?>
YAY you're 13 or above!
<? } ?>开发者_如何学Python;

I am receiving an error saying:

error: Warning: gregoriantojd() expects paramater 1 to be long string

Can anyone help me with this?

Thank you in advance!


Why complicate when you can do it in really simple way:

function dateDiff($dateFormat, $beginDate, $endDate)
{
    $begin = DateTime::createFromFormat($dateFormat, $beginDate);
    $end = DateTime::createFromFormat($dateFormat, $endDate);
    $interval = $begin->diff($end);

    if($interval->y >= 13) 
    {
        echo 'Over 13';
    }
    else
    {
        echo 'Not 13';
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜