Pergunta

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.

Foi útil?

Solução

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));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top