# can someone help explain this...

6 replies to this topic

### #1 brown2005

brown2005
• Members
• 943 posts

Posted 14 July 2006 - 11:39 AM

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

### #2 Kris

Kris
• Staff Alumni
• 2,755 posts
• LocationThe Internet

Posted 14 July 2006 - 11:43 AM

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).

### #3 brown2005

brown2005
• Members
• 943 posts

Posted 14 July 2006 - 11:45 AM

### #4 brown2005

brown2005
• Members
• 943 posts

Posted 14 July 2006 - 11:59 AM

semi u there

### #5 Kris

Kris
• Staff Alumni
• 2,755 posts
• LocationThe Internet

Posted 14 July 2006 - 12:14 PM

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...

### #6 redarrow

redarrow
• Members
• 7,308 posts
• Locationlondon

Posted 14 July 2006 - 12:23 PM

//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);

?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

### #7 GingerRobot

GingerRobot
• Staff Alumni
• 4,086 posts
• LocationUK

Posted 14 July 2006 - 12:25 PM

mine:
```<?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;
?>
```

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users