Sample code change as per your requirement
bool m_flag = false;
DateTime dt = new DateTime(1983, 5, 1, 8, 30, 52);
DateTime dt1 = DateTime.Now;
string strDate = dt.ToString("M/dd/yyyy");
string strDate1 = dt1.ToString("M/dd/yyyy");
if (compareDates(Convert.ToDateTime(strDate1), Convert.ToDateTime(strDate)))
{
m_flag = true;
Response.Write("Valid");
}
else
{
Response.Write("Invalid");
}
<pre>public bool compareDates(DateTime dtHireDate, DateTime dtDateOfBirth)
{
int age = dtHireDate.Year - dtDateOfBirth.Year;
if (dtHireDate.Month < dtDateOfBirth.Month || (dtHireDate.Month == dtDateOfBirth.Month && dtHireDate.Day < dtDateOfBirth.Day))
age--;
if (age >= 18)
{
m_flag = true;
}
else
{
m_flag = false;
}
return m_flag;
}