2019-10-12

calculate age from year of birth

There are two ways:

via php

## 2. in php
You can also use php code, as in the following way
(inspired from this page (https://stackoverflow.com/questions/3776682/php-calculate-age), and _slighty modified_: 

    $dob ="$row[anno_nascita]";
    $age = date_diff(date_create($dob), date_create('now'))->y;
    echo "age: $age years
";

via mysql in phpmyadmin

1.do this sql query:
     select *,year(CURDATE())-year(anno_nascita) age from studenti__classi; 
2. save the result as view
3. and so you will have, in the view, the age (of your students, i.g.) that can work in LibreBase (to connect with that view).

No comments:

Post a Comment

Blog Archive