'Get DateTime by loop with 2 months gap

Hi guys i would like some help how can i achieve to get the date with a gap of 2 months or more so far i did on the code below

final dateNow  = DateTime.now();

DateTime biMonth(DateTime? timeDate, int? add){
 DateTime result = DateTime(dateNow.year,dateNow.month+ add! , dateNow.day);
 return result;
}


 /// The Function
  getDatesGaps(){
    DateTime timeNow = DateTime.now();
    for(int p = 1 ; p < 3 ; p++){
       timeNow = biMonth(timeNow,p);
      log(timeNow.toString());
    }

  }

the result i get

2022-06-19 15:55:00.000
2022-07-19 15:55:00.000

result i want is like this

2022-06-19 15:55:00.000
2022-08-19 15:55:00.000

have a gap with 2 months.



Solution 1:[1]

You could just do

timeNow = biMonth(timeNow,p * 2);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ivo Beckers