Welcome Guest, Not a member yet? Register   Sign In
[solved]calculate age
#1

[eluser]Todlerone[/eluser]
Hello everyone and ty in advance for any help/suggestions. I've tried calculating a persons age from a DOB but I keep getting the warning:

Message: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead

Does ayone have a simple calculate age function that works? TY
#2

[eluser]Bas Vermeulen[/eluser]
Hi, I use:

Code:
$d = $research_day - $birth_day;
$m = $research_month - $birth_month;
$y = $research_year - $birth_year;
if ( $d < 0 ) {
    $m2 = $m - 1;
    $d2 = $d + 30;
    $m = $m2;
    $d = $d2;
}
if ( $m < 0 ) {
    $y2 = $y -1;
    $m3 = $m + 12;
    $y = $y2;
    $m = $m3;
}

This will calculate the age between birth date and research date.
#3

[eluser]danmontgomery[/eluser]
You just need to set the timezone either in php.ini, or somewhere in your script (probably index.php) using ini_set(), just like the message says.
#4

[eluser]Todlerone[/eluser]
TY for your responses. I had placed the
Code:
date_default_timezone_set('America/New_York');
in the index() of each controller that was needed but I moved it to the index.php file...TY

I also found this for calculating age
Code:
floor((time() - strtotime($pt['jcc_demo_DOB']))/(60*60*24*365.2425))
and it works for what I need.

TY all again.




Theme © iAndrew 2016 - Forum software by © MyBB