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


A simple date range


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);


// 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: 15124