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

Answer by Simon Mourier for Difference in months between two dates

$
0
0

Here is a simple solution that works at least for me. It's probably not the fastest though because it uses the cool DateTime's AddMonth feature in a loop:

public static int GetMonthsDiff(DateTime start, DateTime end){    if (start > end)        return GetMonthsDiff(end, start);    int months = 0;    do    {        start = start.AddMonths(1);        if (start > end)            return months;        months++;    }    while (true);}

Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>