What are the potential pitfalls of storing the age in the database alongside the birthday in PHP applications?

Storing the age in the database alongside the birthday in PHP applications can lead to inaccurate data as the age will need to be constantly updated. To solve this issue, it is recommended to calculate the age dynamically based on the birthday whenever it is needed, rather than storing it in the database.

// Calculate age based on birthday
function calculateAge($birthday) {
    $dob = new DateTime($birthday);
    $now = new DateTime();
    $difference = $now->diff($dob);
    return $difference->y;
}

// Example of how to use the calculateAge function
$birthday = "1990-05-15";
$age = calculateAge($birthday);
echo "Age: " . $age;