Basically that is the function that I use to extract the date from the php and modify it:
function getAge()
{
$result= mysql_query("SELECT date_of_birth
FROM controlpanel
WHERE user_id=".$this->userID) or die(mysql_error());
$year="";
if($row=mysql_fetch_array($result))
{
$row['date_of_birth'];
}
}
$row['date_of_birth']; I want to get the year from that row, and check if it is 0000..if it is I want to return return "Not given";.. if it isnt, I want to compare the full date d-m-y to todays date.. in order to get the persons birth date..however, I am not sure what date functions to use..
if( substr($row['date_of_birth'],0,4) == "0000") echo "Not given";
$year = date("Y", $row['date_of_birth']);
if ($year == 0000) {
return "Not given";
}
return date("d m Y", $row['date_of_birth']);
this will give you the 4 digit year from your result: $year = date('Y', strtotime($row['date_of_birth']);
then, you can use a function like the one on the following page to get the age:
http://www.geekpedia.com/code79_Calculate-age-from-birth-date.html
or other solutions: http://www.google.com/search?gcx=w&sourceid=chrome&ie=UTF-8&q=php+get+age+from+birthday
need to add some quotes to declare the 0000 as string cause if you use 0000 not "0000" php will just read it as 0
$year = date("Y", $row['date_of_birth']);
if ($year == "0000") {
return "Invalid year";
}
else{
return "Valid year";
}