I'm looking to highlight the rows when a child is 12 years and older but all the rows are highlighting.
In a nutshell, here is my data.
I'm getting the birth date here:
// getting birth date to a string
$birthDateIn=strtotime($birthDate);
$newDate=date('Y-m-d',$birthDateIn);
I'm getting the age of the child as of today here:
// getting the date difference between birthdate and today
$birthDateIn = new DateTime(''.$newDate.'');
$todayDateIn = new DateTime('today');
$age = $birthDateIn->diff($todayDateIn);
I'm looping through the MySQL query results, and then displaying the age in this format:
echo "<td>" . $age->format('%y years %m months') ."</td>";
Then, this code sets age of child in 2020 (this works):
//Get age Dec 2020
$setDec2020 = new DateTime('2020-12-31');
$ageOnDec2020=$birthDateIn->diff($setDec2020);
Now, here is my problem. I'm using this code to display a GREEN span if the age of the child will be over 12 years of age, otherwise, yellow:
if ($ageOnDec2020 > 12)
{
$ageOnDec2020Display = "<span style='background-color: #98FB98'>".$ageOnDec2020->format('%y') ."</span>";
} else {
$ageOnDec2020Display= "<span style='background-color: #FFFF00'>".$ageOnDec2020->format('%y') ."</span>";
}
Then, I display it as such:
echo "<td>" . $ageOnDec2020Display ."</td>";
The output is that everything is highlighting as yellow when not all of the values are over 12. I think this has to do with "strings" and "integers" in my "if" statement -- but not sure what to do next.
Any ideas?