Is there a better way on multiple addmothe to insert

I have two loops, one to calculate the total and the other to add the number of months as a date using count. I'm looking for a way to replace the 2nd loop with a retrieve of all and then add, is this possible.
1 answers

You can use monthsBetween($date1, date2) to calculate the number of months between two dates, and addMonths($date, 2) to add a number of months to a date (where 2 is the number of months you want to add)