[SOLVED] Show age
Moderator: General Moderators
[SOLVED] Show age
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)
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)
Last edited by Dale on Thu Apr 28, 2005 5:54 pm, edited 1 time in total.
I just checked MYsql has a function also.
STR_TO_DATE(str,format)
http://dev.mysql.com/doc/mysql/en/date- ... tions.html
STR_TO_DATE(str,format)
http://dev.mysql.com/doc/mysql/en/date- ... tions.html
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 how do i change that value to an age?
that's 7 November 1987 in unix timestamp format.
You'll need the current time - that time and convert it from seconds to years.
I think that's right...
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;That gives me:
Code: Select all
1.7390945588112E+16