DateTime DateReg = Convert.ToDateTime(RegTime); DateTime MaxDate = Convert.ToDateTime(MaxTime); DateTime MinDate = Convert.ToDateTime(MinTime); if (!((NowTime.CompareTo(MinDate) >= 0 && NowTime.CompareTo(MaxDate) <= 0) && (DateReg.CompareTo(MinDate) >= 0 && DateReg.CompareTo(MaxDate) <= 0))) { Application.Quit(); }