ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

DateRange

A simple date range

Source

public static class ext
{
    public static IEnumerable<DateTime> GetDateRangeTo(this DateTime self, DateTime toDate)
    {
        var range = Enumerable.Range(0,new TimeSpan(toDate.Ticks - self.Ticks).Days);

        return from p in range
               select self.Date.AddDays(p);
    }
}

Example

// Get next 80 days
IEnumerable<DateTime> dateRange = DateTime.Now.GetDateRangeTo(DateTime.Now.AddDays(80));

Author: P.Revington

Submitted on: 26 apr. 2010

Language: C#

Type: System.DateTime

Views: 15468