How to calculate age based on date of birth in phprad classic 2.7.3++

well hello there ! let us calculate the age based on date of birth!!
let us start by creating our table!
i created one table with the following fields! dob and age

that is it for the database! next thing is to now hide the age field and set it as not required as this will be updated in the background! we only want the date of birth field so that the user can enter when they were born!
click on the add page

then click on age >> TextBoxType and set it as hidden
then click on required and set it to false! like this!

this will just make sure rad doesnt throw errors that age field is required!

you should now have this when you publish your app


! good now finally we finish the app!
go to **page events >> before add of your table **

and write the following code

$age = date_diff(date_create($modeldata['dob']), date_create(date_now()));

$modeldata['age'] = $age->format("%y");

now when you enter your dates you should have this

! that will be all! happy coding!

thanks sir
helping me

1 Like

@thamrin welcome glad to have helped…