du8828
2014-05-04 08:31
浏览 61
已采纳

PHP和Mysql从birthdate中获取存储为varchar的年龄[关闭]

I am creating an application that takes the data from Excel file and stores in MySQL database. Then users can search through candidates based on experience, age, skills etc etc.

My table has the following structure, Name,Surname, Birthdate (stored as varchar), skills, gender, etc etc

What i need is how to compute/figure out/extract the age of the candidates using php/sql?

I am using a drop downlist with following options

<option value="0">--</option>
<option value="eqolderthan20">Equal or older than 20</option>  
<option value="equaloryoungerthan30">Equal or younger than 30</option>  
<option value="olderthan30">Older than 30</option>

Thanks in advance.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duancashi1362 2014-05-04 08:47
    已采纳

    Use strtotime() to get the birthday as a timestamp, then calculate the years based on the difference from the current timestamp. Assuming $birthday is the varchar from your database:

    $age_in_years = floor((time() - strtotime($birthday))/(60*60*24*365));
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题