#### Archived

This topic is now archived and is closed to further replies.

# can someone help explain this...

## Recommended Posts

function age(\$dob)
{

\$date = strtotime(\$dob);

\$today = strtotime(date("d/m/Y"));

echo floor((\$today - \$date) / 31556926);

}

age("30/03/1983");

i know floor rounds down the value but why the  / 31556926

##### Share on other sites
Ahhh, you took that from one of my replies earlier today! There are 31,556,926 seconds in a year - A Unix timestamp is the amount of seconds since the unix epoc (1st of January 1970 ish I think).

semi u there

##### Share on other sites
Sorry, went off to do a bit of research. I'm not 100% sure on this, but I don't think it matters...

Seconds in a normal year: 3600 * 24 * 365 = 31,536,000
Seconds in a leap year: 3600 * 24 * 366 = 31,622,400
Seconds used in my function: 31,556,926 (Reported by Google - "seconds in a year")

Maybe googles answer is some kind of average that accounts for the difference caused by leap years? I really don't know to be honest.

Also, I've realised that my function won't work on all systems - negative timestamps are only supported in PHP5 and on *NIX based operating systems...

##### Share on other sites

//my example playing with the timestamp.

<?

function redarrow(\$birthday){

\$d=date("d")+8;
\$m=date("m")+4;
\$y=date("y")+67;

\$my_birth_date=date("\$d\$m\$y");

\$my_age=\$y-42;

\$birthday=date("y")-31;
\$today_date=date("y-m-d");

if(\$birthday < \$today_date ) {

echo " Your birthday was on the \$my_birth_date I am  \$my_age years old ";

}
}
redarrow(\$birthday);

?>

##### Share on other sites
mine:
[code]
<?php
//all values must be without leading 0. Not sure why,lol
\$current_year = date("Y");
\$current_month = date("n");
\$current_day = date("j");
\$dob_day = 21;
\$dob_month = 9;
\$dob_year = 1989;
\$age = \$current_year-\$dob_year;
if(\$dob_month >= \$current_month){
\$age--;
}

if(\$dob_month == \$current_month && \$dob_day >= \$current_day){
\$age++;
}

echo \$age;
?>
[/code]