Finding the Maximum of two dates.

Posted by Vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 559
Below is the function which will return us maximum date.

Private DateTime GetMaximumDate(DateTime Date1,DateTime Date2)
return (Date1 > Date2 ? Date1 : Date2);

For Example:-We can check max date as:-
protected void Page_Load(object sender, EventArgs e)
Response.Write("Maximum date is:- " + GetMaximumDate(DateTime.Now, DateTime.Now.AddMonths(5)));

In the above code,first parameter is current date and in second date,i have added 5 month,so second date is maximum date.
Maximum date is:- 29/08/2015 10:05:33 AM

Comments or Responses

Login to post response