I'm working on a project which requires me to get the next 7th business day of the month.
I tried the solution below but I'm not satisfied with the result, furthermore, it doesn't take into account the holidays (in France). I guess I could use an array with most of the holidays and filter through it.
Could you give me hints or a sample of code to correct me? Best regards.
DateTime seventhBusinessDayNextMonth = new DateTime(DateTime.Today.AddMonths(1).Year, DateTime.Today.AddMonths(1).Month, 7);
DateTime seventhBusinessDayCurrentMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 7);
if (DateTime.Today.Day == 7 && DateTime.Today.DayOfWeek != DayOfWeek.Saturday && DateTime.Today.DayOfWeek != DayOfWeek.Sunday)
{
this.Data.nextSeventhBusinessDay = DateTime.Now.ToString("dd/MM/yyyy");
}
else if (DateTime.Today.Day <= 7 && seventhBusinessDayCurrentMonth.DayOfWeek == DayOfWeek.Saturday)
{
this.Data.nextSeventhBusinessDay = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 9).ToString("dd/MM/yyyy");
}
else if (DateTime.Today.Day <= 7 && DateTime.Today.DayOfWeek == DayOfWeek.Sunday)
{
this.Data.nextSeventhBusinessDay = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 8).ToString("dd/MM/yyyy");
}
else if (DateTime.Today.Day > 7 && seventhBusinessDayNextMonth.DayOfWeek == DayOfWeek.Saturday)
{
this.Data.nextSeventhBusinessDay = new DateTime(DateTime.Today.AddMonths(1).Year, DateTime.Today.AddMonths(1).Month, 9).ToString("dd/MM/yyyy");
}
else if (DateTime.Today.Day > 7 && seventhBusinessDayNextMonth.DayOfWeek == DayOfWeek.Sunday)
{
this.Data.nextSeventhBusinessDay = new DateTime(DateTime.Today.AddMonths(1).Year, DateTime.Today.AddMonths(1).Month, 8).ToString("dd/MM/yyyy");
}
else
{
this.Data.nextSeventhBusinessDay = seventhBusinessDayNextMonth.ToString("dd/MM/yyyy");
}