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

Answer by Wayne for Difference in months between two dates

$
0
0

This is from my own library, will return the difference of months between two dates.

public static int MonthDiff(DateTime d1, DateTime d2){    int retVal = 0;    // Calculate the number of years represented and multiply by 12    // Substract the month number from the total    // Substract the difference of the second month and 12 from the total    retVal = (d1.Year - d2.Year) * 12;    retVal = retVal - d1.Month;    retVal = retVal - (12 - d2.Month);    return retVal;}

Viewing all articles
Browse latest Browse all 46

Trending Articles



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