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

Answer by Konstantin Chernov for Difference in months between two dates

$
0
0

Here's how we approach this:

public static int MonthDiff(DateTime date1, DateTime date2){    if (date1.Month < date2.Month)    {        return (date2.Year - date1.Year) * 12 + date2.Month - date1.Month;    }    else    {        return (date2.Year - date1.Year - 1) * 12 + date2.Month - date1.Month + 12;    }}

Viewing all articles
Browse latest Browse all 46

Trending Articles



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