There are two text fields and date verification with the condition if more than a year.
The first current date and the second end date (we fill in the field ourselves).
Need verification if more than 12 months then an error
Code:
DateTime dateBegin = DateTime.Parse(txtDateBegin.Text); DateTime dateEnd = DateTime.Parse(txtDateEnd.Text); TimeSpan sp = dateEnd - dateBegin; if (DateTime.IsLeapYear(dateEnd.Year)) { if (sp.Days > 366) { args.IsValid = false; CV_InsDates.ErrorMessage = "Ошибка"; } } else { if (sp.Days > 365) { args.IsValid = false; CV_InsDates.ErrorMessage = "Ошибка"; } } Will this check be correct (check only on the end date)?
With what number to compare 366 or 365, how to determine how many days in a year?
asp.nethere? You can remake the question about dates (let's say on the method that returnsbooland remove the specifics ofasp.net). 2. Indicate about your desire for the code to return thebool: whether the difference is less than 1 year. Then your question will be more general and useful. - Vadim Ovchinnikov