Hi
i have month and year like
int lastpaidyear = Convert.ToInt32(lastpaidmonth.Rows[0][1].ToString()); ex:8
int lastpaismonth = Convert.ToInt32(lastpaidmonth.Rows[0][2].ToString());ex:2012
and
int selectmonth = Convert.ToInt32( ddlmonth.SelectedValue.ToString());ex:10
int selectyear = Convert.ToInt32( ddlyear.SelectedValue.ToString());ex:2015
now i want total month ?
please help me
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Francis SusaimichaelRank #466 · 5.4K reputationPosted Nov 3, 2015, 3:32 AM EST
Jean-Claude ColetteRank #2,678 · 520 reputationPosted Nov 3, 2015, 4:39 AM EST
DateTime second = new DateTime(2015, 10, 21);
DateTime earlierDate = (first > second) ? second.Date : first.Date;
DateTime laterDate = (first > second) ? first.Date : second.Date;
number_month = (number_month < 0) ? 0 : number_month;
//default rounding of the number of plain month completely included between the 2 dates
int remaining_months = 1;
while (earlierDate.AddMonths(remaining_months) <= laterDate)
{
remaining_months++;
}