Hi akhter,
Please refer below sample.
HTML
<table>
<tr>
<td>Start Date :</td>
<td>
<asp:TextBox ID="txtStartDate" runat="server" />
</td>
</tr>
<tr>
<td>End Date</td>
<td>
<asp:TextBox ID="txtEnddate" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="Calculate" />
</td>
</tr>
</table>
<asp:Label ID="lblDays" runat="server"></asp:Label>
Namespace
C#
using System.Globalization;
VB.Net
Imports System.Globalization
Code
C#
protected void Calculate(object sender, EventArgs e)
{
TimeSpan i = new TimeSpan(0, 0, 0);
DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim(), new CultureInfo("en-Gb"));
DateTime endDate = Convert.ToDateTime(this.txtEnddate.Text.Trim(), new CultureInfo("en-Gb"));
i += endDate.Subtract(startDate);
int days = i.Days + 1;
this.lblDays.Text = "Days Count is : " + days.ToString();
}
VB.Net
Protected Sub Calculate(ByVal sender As Object, ByVal e As EventArgs)
Dim i As TimeSpan = New TimeSpan(0, 0, 0)
Dim startDate As DateTime = Convert.ToDateTime(Me.txtStartDate.Text.Trim(), New CultureInfo("en-Gb"))
Dim endDate As DateTime = Convert.ToDateTime(Me.txtEnddate.Text.Trim(), New CultureInfo("en-Gb"))
i += endDate.Subtract(startDate)
Dim days As Integer = i.Days + 1
Me.lblDays.Text = "Days Count is : " & days.ToString()
End Sub
Screenshot