Page 1 of 1

[SOLVED] Show age

Posted: Thu Apr 28, 2005 3:03 pm
by Dale
I have 3 fields in my database

DOBDAY
DOBMONTH
DOBYEAR

So when a person registers it adds it as:
17
November
1987

But i wanted to know, how i can get them 3 fields to be converted and shows the age. (eg; 17)

Posted: Thu Apr 28, 2005 3:13 pm
by hawleyjr
Because your month is stored as a sting use the strtotime function in PHP.

And then do a date comparison.

Posted: Thu Apr 28, 2005 3:16 pm
by hawleyjr
I just checked MYsql has a function also.

STR_TO_DATE(str,format)

http://dev.mysql.com/doc/mysql/en/date- ... tions.html

Posted: Thu Apr 28, 2005 3:53 pm
by Dale
hawleyjr wrote:Because your month is stored as a sting use the strtotime function in PHP.

And then do a date comparison.

I'll use this PHP way. However now that (eg; my birthday) shows a whole number:

Code: Select all

<?php
$dob = strtotime("7 November 1987");
echo $dob;
?>
Now that shows: 563259600
Now how do i change that value to an age?

Posted: Thu Apr 28, 2005 4:12 pm
by Skara
that's 7 November 1987 in unix timestamp format.

You'll need the current time - that time and convert it from seconds to years.

Code: Select all

$age = (time() - strtotime("7 November 1987")) * 60 * 60 * 24 * 365;
I think that's right...

Posted: Thu Apr 28, 2005 4:14 pm
by Dale
That gives me:

Code: Select all

1.7390945588112E+16

Posted: Thu Apr 28, 2005 4:21 pm
by Skara
hahaha. change all the * to /
XD goofy me.

Posted: Thu Apr 28, 2005 4:24 pm
by Dale
Skara wrote:hahaha. change all the * to /
XD goofy me.

Cool, that works, now how do i make the result as a whole number?

Posted: Thu Apr 28, 2005 5:40 pm
by Skara
floor($foo);

Posted: Thu Apr 28, 2005 5:54 pm
by Dale
Skara wrote:floor($foo);
Thank you so! much! *kiss*