Page 1 of 1

How to calculate ages based on DOB?

Posted: 2015-11-02 14:01
by sueirna
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

Re: How to calculate ages based on DOB?

Posted: 2015-11-02 20:59
by a.gneady

Re: How to calculate ages based on DOB?

Posted: 2015-11-08 15:51
by sueirna
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);
}

?>

Re: How to calculate ages based on DOB?

Posted: 2015-11-09 02:45
by sueirna
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