How to calculate ages based on DOB?

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
sueirna
Posts: 9
Joined: 2014-02-06 23:59

How to calculate ages based on DOB?

Post by sueirna » 2015-11-02 14:01

How to calculate age based on date of birth? I want my form when user fill DOB, automatically populate the age field,...

Can someone show me?, i am using appgini 5.31. tq

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: How to calculate ages based on DOB?

Post by a.gneady » 2015-11-02 20:59

:idea: AppGini plugins to add more power to your apps:

sueirna
Posts: 9
Joined: 2014-02-06 23:59

Re: How to calculate ages based on DOB?

Post by sueirna » 2015-11-08 15:51

i ve tried, it's not work for me. Here is the code on hook. My table name is 'failj' , DOB=tlahir and Age=Umur, Please help me how to do it, tq...

<?php
// For help on using hooks, please refer to http://bigprof.com/appgini/help/working ... tion/hooks

function failj_init(&$options, $memberInfo, &$args){

return TRUE;
}

function failj_header($contentType, $memberInfo, &$args){
$header='';

switch($contentType){
case 'tableview':
$header='';
break;

case 'detailview':
$header='';
break;

case 'tableview+detailview':
$header='';
break;

case 'print-tableview':
$header='';
break;

case 'print-detailview':
$header='';
break;

case 'filters':
$header='';
break;
}
updateAge("MONTH(tlahir)=" . date('n'));
return $header;
}

function failj_footer($contentType, $memberInfo, &$args){
$footer='';

switch($contentType){
case 'tableview':
$footer='';
break;

case 'detailview':
$footer='';
break;

case 'tableview+detailview':
$footer='';
break;

case 'print-tableview':
$footer='';
break;

case 'print-detailview':
$footer='';
break;

case 'filters':
$footer='';
break;
}

return $footer;
}

function failj_before_insert(&$data, $memberInfo, &$args){

return TRUE;
}

function failj_after_insert($data, $memberInfo, &$args){
updateAge("ID='{$data['selectedID']}'");
return TRUE;
}

function failj_before_update(&$data, $memberInfo, &$args){

return TRUE;
}

function failj_after_update($data, $memberInfo, &$args){
updateAge("ID='{$data['selectedID']}'");

return TRUE;
}

function failj_before_delete($selectedID, &$skipChecks, $memberInfo, &$args){

return TRUE;
}

function failj_after_delete($selectedID, $memberInfo, &$args){

}

function failj_dv($selectedID, $memberInfo, &$html, &$args){

}

function failj_csv($query, $memberInfo, &$args){

return $query;
}
function failj_batch_actions(&$args){

return array();
}

function updateAge($where = ''){
$sql = "update `failj` set `Umur` = round(datediff('".date('Y-m-d')."', `tlahir`) / 365.25)";
if($where) $sql .= "where $where";
sql($sql, $eo);
}

?>

sueirna
Posts: 9
Joined: 2014-02-06 23:59

Re: How to calculate ages based on DOB?

Post by sueirna » 2015-11-09 02:45

here is my form looks like

https://www.facebook.com/photo.php?fbid ... =3&theater

when i change the year, i want it automatically calculate age on 'Umur' Field by its self.tq

Post Reply