Hi!

Our customer has a data model where the data is represented by date and hour. Dates are normal dates like "2014-01-01" and there is a separate property on the model for the Hour, from 1 to 24.

How should I write a simple method that accepts startdate, starthour, enddate, endhour and loop through each hour?

I tried using this code:
Code:
 public List<DateTime> GetAllHoursInInterval(DateTime startDate, int startHour, DateTime endDate,
            int endHour)
        {
            var dates = new List<DateTime>();
          
            for (var date = startDate.AddHours(startHour); date <= endDate.AddHours(endHour); date = date.AddHours(1))
            {
                Debug.WriteLine("Date: " + date.ToShortDateString());
                Debug.WriteLine("Hour: " + (date.Hour));
                dates.Add(date);
            }
            return dates;
        }
But there is a mismatch in the datetime hours and the hours in the data model, since the datetime likes to start from hour 0 to 23.

I want to work with the model hour, but in the loop I guess I should stick with the DateTime hours...

Preferrably this method should handle daylight savings and stuff...

/H