Forums

how to show actual age in table column based on birthdays

samir1903 21 May, 2019
i want to show age of each person in table based on birthday, as well as export as a cv
i think i need php but i confused
healyhatman 21 May, 2019
Yes you will need PHP. Your column view should be age:{fn:php_block_name} with your PHP block used to calculate the age. Remember though that you can't use shortcodes in PHP blocks.
$birthdate = $this->get("tablename.row.model.field");
$age = // calculate age here
echo $age;
That will display your age in the column.

To get it in the CSV you'll want to either have your read data action include a calculated age directly, or loop through the read data in PHP and add the age to each row before using your export CSV action.
samir1903 21 May, 2019
that works perfectly thanks but how can ı export this
i use another db read to export data
if i put age there model.age couldnt find error
healyhatman 21 May, 2019
Well no of course not. Like I said to export it to CSV you need to either:

1) Read data, then use PHP to loop through and add an "age" field to each row of the array, then use the array you return from the PHP block as the data source for your CSV export action
or
2) Get the age as part of the data read itself. http://www.gizmola.com/blog/archives/archives/107-Calculate-a-persons-age-in-a-MySQL-query.html

OR THERE IS AN OPTION 3!!!
DON'T export the age at all! Because as soon as you export it the age becomes potentially incorrect anyway. Just recalculate the age wherever it is you're using the CSV.
This topic is locked and no more replies can be posted.