Creating date sequence between two given dates - fails on febuary : Im using the following method to create a date sequence between two given dates;

        public List<DateTime> dateSeq(DateTime startDate, DateTime endDate)
        {

            List<DateTime> allDates = new List<DateTime>();
            
            for (DateTime date = startDate; date <= endDate; date = date.AddMonths(1))
            allDates.Add(date);

            return allDates;
        }


Creating a date sequence while incrementing 1 month, when the given date for example are: 

startDate: 2017-01-01 
endDate: 2017-05-01 

the sequence i get is fine:

2017-01-01
2017-02-01
2017-03-01
2017-04-01
2017-05-01

But when the given dates are:

startDate: 2017-01-31 
endDate: 2017-05-31

The sequence i get fail when passing febuary setting the rest of the months sequence on the 28th day:

2017-01-31
2017-02-28
2017-03-28
2017-04-28
2017-05-28


Can someone please explain why is that?


Thanks!

