Hi,
Please refer below sample.
HTML
<div>
From :
<asp:TextBox ID="txtFromDate" runat="server"></asp:TextBox>
<br />
To :
<asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
<asp:Button ID="btnInsert" Text="Insert" runat="server" OnClick="btnInsert_Click" />
<asp:Label ID="lblMessage" runat="server" />
</div>
Namespaces
C#
using System.Globalization;
using System.Data;
VB.Net
Imports System.Globalization
Imports System.Data
Code
C#
protected void btnInsert_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("FromDate", typeof(string)), new DataColumn("ToDate", typeof(string)) });
dt.Rows.Add("01.08.2018", "15.08.2018");
DateTime fromdate = DateTime.ParseExact(txtFromDate.Text, "dd.MM.yyyy", CultureInfo.CurrentUICulture);
DateTime ToDate = DateTime.ParseExact(txtToDate.Text, "dd.MM.yyyy", CultureInfo.CurrentUICulture);
int fromDay = fromdate.Day;
int fromMonth = fromdate.Month;
int FromYear = fromdate.Year;
string dtFromDay = dt.Rows[0]["FromDate"].ToString();
string[] dtFromsplit = dtFromDay.Split('.');
string dtToDay = dt.Rows[0]["ToDate"].ToString();
string[] dtTosplit = dtToDay.Split('.');
int toDay = ToDate.Day;
int toMonth = ToDate.Month;
int toYear = ToDate.Year;
if (fromDay >= Convert.ToInt16(dtFromsplit[0]) && fromMonth >= Convert.ToInt16(dtFromsplit[1]) && FromYear >= Convert.ToInt16(dtFromsplit[2]) && toDay >= Convert.ToInt16(dtTosplit[0]) && toMonth >= Convert.ToInt16(dtTosplit[1]) && FromYear >= Convert.ToInt16(dtTosplit[2]))
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Valid Input')", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Invalid Input')", true);
}
}
VB.Net
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("FromDate", GetType(String)), New DataColumn("ToDate", GetType(String))})
dt.Rows.Add("01.08.2018", "15.08.2018")
Dim fromdate As DateTime = DateTime.ParseExact(txtFromDate.Text, "dd.MM.yyyy", CultureInfo.CurrentUICulture)
Dim ToDate As DateTime = DateTime.ParseExact(txtToDate.Text, "dd.MM.yyyy", CultureInfo.CurrentUICulture)
Dim fromDay As Integer = fromdate.Day
Dim fromMonth As Integer = fromdate.Month
Dim FromYear As Integer = fromdate.Year
Dim dtFromDay As String = dt.Rows(0)("FromDate").ToString()
Dim dtFromsplit As String() = dtFromDay.Split("."c)
Dim dtToDay As String = dt.Rows(0)("ToDate").ToString()
Dim dtTosplit As String() = dtToDay.Split("."c)
Dim toDay As Integer = ToDate.Day
Dim toMonth As Integer = ToDate.Month
Dim toYear As Integer = ToDate.Year
If fromDay >= Convert.ToInt16(dtFromsplit(0)) AndAlso fromMonth >= Convert.ToInt16(dtFromsplit(1)) AndAlso FromYear >= Convert.ToInt16(dtFromsplit(2)) AndAlso toDay >= Convert.ToInt16(dtTosplit(0)) AndAlso toMonth >= Convert.ToInt16(dtTosplit(1)) AndAlso FromYear >= Convert.ToInt16(dtTosplit(2)) Then
ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('Valid Input')", True)
Else
ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('Invalid Input')", True)
End If
End Sub
Screenshot
![](https://i.imgur.com/YGsSCcJ.gif)