How To Calculate Due Days Excluding Weekends In C#.NET
Here's a function that will calculate the number of days excluding weekends. The parameters passed are the priority which contains number of days and the current date. Sample priorities are 'High[1 day]', 'Average [2 days]' and 'Low [5 days]'. The function then uses Regex to extract the whole numbers from the priority string to be used for incrementing the number of days.
public DateTime RecalculateDueDate(string priority, DateTime Today) { int days; int count; DateTime dueDate; count = 0; dueDate = Today; days = int.Parse(Regex.Replace(priority, "[^0-9]", "")); while (count < days) { dueDate = dueDate.AddDays(1); if ((int)dueDate.DayOfWeek != 0 && (int)dueDate.DayOfWeek != 6) count++; } return dueDate; }
Comments
Post a Comment