I have a program where there are staff records, it has a date of first appointment and also a date of birth.
There are two modes of retirement in the civil service, if you have served upto 35 years, you will retire, but if your date of first appointment + 35 years is more than 60years of your age, you will have to retire when you are 60, how do i do this calculation please?
$projected_year_of_retirement_based_on_years_of_first_appt = $years_since_first_appointment + 35;
if( by the time $projected_year_of_retirement_based_on_years_of_first_appt you are more than 60 years already)
$you_new_retirement_date will now be 60years - $your_current_age, then add the result to your $years_since_first_appointment
but if($projected_year_of_retirement_based_on_years_of_first_appt falls before you are 60 years old)
$you_new_retirement_date will now be $projected_year_of_retirement_based_on_years_of_first_appt
Carbon has a diffInYears helper to get you going (my guess would be that this is the hard math for you, and not the "add 35 to another number" part :))
Short of someone commiting the functioning code to your codebase you've been given the solution in several ways -- and you even pseudocoded the logic for it yourself.