Try this:
protected string CheckDateErrors(string dateGiven)
{
DateTime userDate = DateTime.Parse(dateGiven);
int userYear = userDate.Year;
int userMonth = userDate.Month;
int userDay = userDate.Day;
if (userDate.CompareTo(DateTime.Now) > 0)
{
return "* Cannot Enter Future Dates;";
}
else if (userDate.CompareTo(DateTime.Now) <= 0)
{
int difference = DateTime.Today.Year - userYear;
if (userYear < (DateTime.Today.Year - 1))
{
return "* Cannot Enter Past One Year: Compared Years;";
}
else if ((difference == 1) &&
(userMonth < DateTime.Today.Month))
{
return "* Cannot Enter Past One Year: Compared Months;";
}
else if ((difference == 1) &&
(userMonth >= DateTime.Today.Month) &&
(userDay < DateTime.Today.Day))
{
return "* Cannot Enter Past One Year: Compared Days";
}
return "none";
}
return "none";
}
Found it here[^]