How can I count the number of holidays from database between 2 days
I already count the number of business days but how can i minus to week days the number of holidays counted between 2 days.
Assuming that I have a Holidays
table with
- Halloween 11-01
- Christmas 12-25
Dates:
- start date = 10-25
- end date = 01-30
Answer should be: Business days - Holiday Number between 2 dates ;
Here's my code:
public static void GetBusinessDays(DateTime startD, DateTime endD)
{
double calcBusinessDays =
1 + ((endD - startD).TotalDays * 5 -
(startD.DayOfWeek - endD.DayOfWeek) * 2) / 7;
if (endD.DayOfWeek == DayOfWeek.Saturday) calcBusinessDays--;
if (startD.DayOfWeek == DayOfWeek.Sunday) calcBusinessDays--;
MessageBox.Show(" " + calcBusinessDays);
}
from this link :Calculate the number of business days between two dates?
Button:
private void button1_Click(object sender, EventArgs e)
{
GetBusinessDays(Convert.ToDateTime(metroDateTime1.Value.ToString("yyyy-MM-dd")), Convert.ToDateTime(metroDateTime2.Value.ToString("yyyy-MM-dd")));
}
PS: I'm new to c#