Hi Vincent,
Thank you for your input.
You are correct, after looking at this with a fresh start it occured to me to do just as you are suggesting and it works fine!
The elaborate IF was to get the age of the user for the dob column. I have resolved to using my original PHP script(below) to do this. Is there an easier way to get age values?
Thanks,
Kevin
Function age($age)
{
/+--------------------------------------------+
| Calculate the age of the featured profile |
| takes the dob in the form m/d/yyyy from |
| MySQL table as DATE_FORMAT(dob, '%m/%d/%Y')|
| as arugument $age. |
| Returns $years (years old) |
+--------------------------------------------+/
$currDate = getdate();
list($myDob["mon"], $myDob["mday"], $myDob["year"]) = split("[/.-]", $age);
$years = ($currDate["year"] - $myDob["year"]);
if($myDob["mon"] > $currDate["mon"]){
$years--;
} else {
if($myDob["mday"] > $currDate["mday"]){
$years--; //it's not your birthday yet, years = years - 1
} elseif ($myDob["mday"] == $currDate["mday"]){
$years .= " - Happy BirthDay!";
}
}
Return($years);
}
vincent wrote:
You can't do a 'WHERE' on a virtual column, only on real columns.
But why the elaborate IF sequence?
If you want to fetch dates that are between X and Y years old you can just calculate the date of the lower and upper limits (dob of 18y/o and dob of 39y/o)
and then select records like:
SELECT *
FROM users
WHERE dob<upper_limit AND dob>lower_limit;