ijtzib
Posts: 24
|
Posted: 07/10/2012, 3:12 PM |
|
Hi guys,
I have a function here that is working that calculates the age....
------------------------------------------------------------
function getAge($DOB) {
//calculate years of age (input string: YYYY-MM-DD)
list($year, $month, $day) = explode("-", $DOB);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0 || $month_diff < 0)
$year_diff--;
return $year_diff;
}
---------------------------------------------------------------
Im wanting to display the age in record's label like this....
$Container->Age->SetValue(getAge($Container->DOB->GetText()));
So why am I getting '2012' ? and not the Age?
Any one can tell me what Im doing wrong...?
Thanks
ijtzib
|
|
|
ckroon
Posts: 869
|
Posted: 07/10/2012, 4:34 PM |
|
Try
$Container->DOB->GetValue();
_________________
Walter Kempees...you are dearly missed. |
|
|
ijtzib
Posts: 24
|
Posted: 07/11/2012, 8:18 AM |
|
Thank you for your response ckroon...
but still no success...
Or is there another way to calculate Age?
ijtzib
|
|
|
ijtzib
Posts: 24
|
Posted: 07/11/2012, 8:18 AM |
|
Thank you for your response ckroon...
but still no success...
Or is there another way to calculate Age?
ijtzib
|
|
|
ijtzib
Posts: 24
|
Posted: 07/11/2012, 8:18 AM |
|
Thank you for your response ckroon...
but still no success...
Or is there another way to calculate Age?
ijtzib
|
|
|
ijtzib
Posts: 24
|
Posted: 07/11/2012, 8:19 AM |
|
Thank you for your response ckroon...
but still no success...
Or is there another way to calculate Age?
ijtzib
|
|
|
ijtzib
Posts: 24
|
Posted: 07/11/2012, 8:19 AM |
|
Sorry for the duplicates...error on page....
ijtzib
|
|
|
saseow
Posts: 744
|
Posted: 07/11/2012, 9:27 PM |
|
The function you are using does work but it can return an age that is i year less than it should do. Here is a very comprehensive article and function which does return a correct age:
http://www.karlrixon.co.uk/writing/calculating-age-from...f-birth-in-php/
|
|
|
MaFi
Posts: 49
|
Posted: 07/11/2012, 11:57 PM |
|
May it helps if you calculate the exact age direct in the sql query.
If you have a field Birthday you can use:
(YEAR(CURDATE())-YEAR(Birthday)) - (RIGHT(CURDATE(),5) < RIGHT(Birthday,5)) AS Age
Martin
|
|
|
ijtzib
Posts: 24
|
Posted: 07/12/2012, 2:48 PM |
|
Hi Guys thank you for your response...
I used saseow example. The second function and it worked!
|
|
|