CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 SOLVED - Calculating Age

Print topic Send  topic

Author Message
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
View profile  Send private message
ckroon

Posts: 869
Posted: 07/10/2012, 4:34 PM

Try

$Container->DOB->GetValue();

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
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
View profile  Send private message
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
View profile  Send private message
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
View profile  Send private message
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
View profile  Send private message
ijtzib

Posts: 24
Posted: 07/11/2012, 8:19 AM

Sorry for the duplicates...error on page....

ijtzib
View profile  Send private message
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/
View profile  Send private message
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
View profile  Send private message
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!

:-) :-)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.