If you're still looking for a proper solution to ensure that two dates fall within a given maximum number of months—including variations in month lengths (such as February)—I’ve come up with the following approach that might help.
This hides the overcomplexity of the other solutions where you have to do extra calculations based on moths or to calculate the exact timespan.
For example given a dateTo as 31/03/2025 and maxMonths of 6 the dateFrom should end up to 30/09/2024 as there is no 31 date on September, so this code will return the result as true whereas if you put the dateFrom as 29/09/2025 this will end up to false. The opposite way around also works (ex. DateTo is 28 of February)
public static bool IsWithinMonths(DateTime dateFrom, DateTime dateTo, int maxMonths) { // Ensure dateFrom is before or equal to dateTo if (dateFrom > dateTo) return false; // Subtract maxMonths from dateTo DateTime minAllowedDate = dateTo.AddMonths(-maxMonths); // Validate if dateFrom is within range return dateFrom >= minAllowedDate; }