validate age before registering a user to check if

2020-02-15 08:12发布

hi i have to develop a form which takes user age and calculates age and if over 18 procedds to take him to registeration form

my question is has i am using zend framework how to implement it when its not supposed to interact with model much and their is no data in database

how can i validate age of the person

i m trying to use this code

$data = array (  'dob' => date ( "Y-m-d" ));

$select = $db
    ->select()
    ->from('data', array(
        'id',
        'age' => new Zend_Db_Expr("DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(dob)), '%Y')+0"))) 

can i use an array ? please help me friendshow should be this query

1条回答
男人必须洒脱
2楼-- · 2020-02-15 08:52

I don't quite understand your question... Are you having trouble calculating the age from a DOB?

If so, this should take care of your problem:

function Age($date = 'now')
{
    return intval(substr(date('Ymd') - date('Ymd', strtotime($date)), 0, -4));
}

var_dump(Age('1975-04-25')); // int(36)

if (Age('1975-04-25') >= 18)
{
    // proceed to registration
}
查看更多
登录 后发表回答