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

Answer by reza akhlaghi for Difference in months between two dates

$
0
0

I wrote a function to accomplish this, because the others ways weren't working for me.

public string getEndDate (DateTime startDate,decimal monthCount){    int y = startDate.Year;    int m = startDate.Month;    for (decimal  i = monthCount; i > 1; i--)    {        m++;        if (m == 12)        { y++;            m = 1;        }    }    return string.Format("{0}-{1}-{2}", y.ToString(), m.ToString(), startDate.Day.ToString());}

Viewing all articles
Browse latest Browse all 46

Trending Articles



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