The code is pretty simple:
var someDate = DateTime.Now; // could be any date set some other way
if(someDate > end) return false;
var checkDate = start;
while(checkDate < end)
{
if(checkDate.Month == someDate.Month && checkDate.Year == someDate.Year)
return true;
checkDate = checkDate.AddMonths(periodicity);
}
return false;
All you’re doing is making sure someDate
isn’t past end
and that the difference in months between the start
and someDate
is divisible evenly by the periodicity.
5
solved Periodicity of events [closed]