I have two dates:
DateTime date_of_submission = Convert.ToDateTime(DateTime.Now.ToString(\"MM/dd/yyyy\"));
DateTime _effective_date = Convert.ToDateTime(Text
You can compare two datetime values with each other as you normally compare.
So, you can do the following :-
if(date_of_effective_date.CompareTo(date_of_submission_date.AddDays(90)) <= 0)
{
//Correct
}
You can subtract two dates, and get a TimeSpan :
TimeSpan difference = _effective_date - date_of_submission;
if(difference.TotalDays > 90)
{
// Bingo!
}
Something like...
TimeSpan difference = _effective_date - date_of_submission;
double days = difference.TotalDays;
if (days > 0 && days <= 90)
{
//valid
}
Though there are several effective solution, It could be one for future searchers
DateTime date_of_submission = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"));
DateTime _effective_date = Convert.ToDateTime(TextBox32.Text);
DateTime lastPossibleEffectiveDate = _effective_date.AddDays(90);
int result = DateTime.Compare(_effective_date,lastPossibleEffectiveDate);
if (result <= 0)
Console.WriteLine("Valid Date");
else if (result > 0 )
Console.WriteLine("Not Valid effective date");
var days = (_effective_date - date_of_submission).Days;
This is a sample to compare datetime. you can change according to your requirement
DateTime dtFromDate = DateTime.ParseExact(TextBoxFromDate.Text, "dd/MM/yyyy",
CultureInfo.InvariantCulture);
DateTime dtToDate = DateTime.ParseExact(TextBoxToDate.Text, "dd/MM/yyyy",
CultureInfo.InvariantCulture);
TimeSpan difference = dtFromDate - dtToDate;
double days = difference.TotalDays;
if (days > 0)
{
DivFormError.InnerText = "“From Date” cannot be greater than “To Date”";
}