public static IEnumerable <int> DateRange(this int beginDate, int endDate, int step = 1) { int fromDate = beginDate; int toDate = endDate; while ((step >= 0 ? (fromDate <= toDate) : (fromDate >= toDate))) { yield return(fromDate); fromDate = fromDate.AddDays(step); } }
public static DateTime GetWorkingDay(DateTime month, int day) { month = month.AddDays(-(month.Day - 1)); DateTime _month = month.Date; //MessageBox.Show(month.Day.ToString()); for (int daysCount = 0; month.Day < DateTime.MaxValue.Month; month = month.AddDays(1)) { if (month.DayOfWeek != DayOfWeek.Sunday && month.DayOfWeek != DayOfWeek.Saturday) { daysCount++; } // If the working days reach [day], return the current count days if (daysCount >= day) { return(month); } } return(_month); }
public static int AddWeeks(this int date, int weeks) { return(date.AddDays(7 * weeks)); }