Wednesday, September 7, 2011

Date difference in months asp.net,C#

This exercise will teach how to get the months difference between  From date and  To date.


private static int monthDifference(DateTime startDate, DateTime endDate)
{
int monthsApart = 12 * (startDate.Year - endDate.Year) + startDate.Month - endDate.Month;
return Math.Abs(monthsApart);
}

Hope this helps...

No comments:

Post a Comment

Popular Posts