Quantcast
Channel: Difference in months between two dates - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by Sukanta for Difference in months between two dates

$
0
0
public static int PayableMonthsInDuration(DateTime StartDate, DateTime EndDate){    int sy = StartDate.Year; int sm = StartDate.Month; int count = 0;    do    {        count++;if ((sy == EndDate.Year) && (sm >= EndDate.Month)) { break; }        sm++;if (sm == 13) { sm = 1; sy++; }    } while ((EndDate.Year >= sy) || (EndDate.Month >= sm));    return (count);}

This solution is for Rental/subscription calculation, where difference doesn't means to be subtraction, it's meant to be the span in within those two dates.


Viewing all articles
Browse latest Browse all 46

Trending Articles