Hi kankon,
Please refer below sample.
HTML
<asp:TextBox runat="server" ID="txtBox1" />
<asp:TextBox runat="server" ID="txtbox2" />
<br /><asp:Button Text="Submit" runat="server" OnClick="Submit_OnClick" />
<br /><asp:Label Text="" runat="server" ID="lblLabel1" />
Namespace
C#
using System;
using System.Collections.Generic;
VB.Net
Imports System
Imports System.Collections.Generic
Code
C#
protected void Submit_OnClick(object sender, EventArgs e)
{
DateTime d1 = Convert.ToDateTime(txtBox1.Text);
DateTime d2 = Convert.ToDateTime(txtbox2.Text);
var totalDays = (d2 - d1).Days;
int wd = 0;
for (int x = 0; x <= totalDays; x++)
{
DateTime currendDate = d1.AddDays(x);
if (currendDate.DayOfWeek != DayOfWeek.Friday)
{
if (!Holiday().Contains(d1.AddDays(x)))
{
wd += 1;
}
}
}
lblLabel1.Text = wd.ToString();
}
private List<DateTime> Holiday()
{
List<DateTime> dates = new List<DateTime>();
dates.Add(new DateTime(2019, 01, 01));
dates.Add(new DateTime(2019, 02, 25));
dates.Add(new DateTime(2019, 02, 26));
dates.Add(new DateTime(2019, 04, 04));
dates.Add(new DateTime(2019, 08, 31));
dates.Add(new DateTime(2019, 09, 11));
return dates;
}
VB.Net
Protected Sub Submit_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Dim d1 As DateTime = Convert.ToDateTime(txtBox1.Text)
Dim d2 As DateTime = Convert.ToDateTime(txtbox2.Text)
Dim totalDays = (d2 - d1).Days
Dim wd As Integer = 0
For x As Integer = 0 To totalDays
Dim currendDate As DateTime = d1.AddDays(x)
If currendDate.DayOfWeek <> DayOfWeek.Friday Then
If Not Holiday().Contains(d1.AddDays(x)) Then
wd += 1
End If
End If
Next
lblLabel1.Text = wd.ToString()
End Sub
Private Function Holiday() As List(Of DateTime)
Dim dates As List(Of DateTime) = New List(Of DateTime)()
dates.Add(New DateTime(2019, 1, 1))
dates.Add(New DateTime(2019, 2, 25))
dates.Add(New DateTime(2019, 2, 26))
dates.Add(New DateTime(2019, 4, 4))
dates.Add(New DateTime(2019, 8, 31))
dates.Add(New DateTime(2019, 9, 11))
Return dates
End Function