.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Count number of months between two date

Posted By:Hiren Soni       Posted Date: August 11, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

here i will provide you code for get number of month between two month.

DateTime d1 = new DateTime(2002, 1, 1);  

DateTime d2 = new DateTime(2000, 10, 1);  

int M = Math.Abs((d1.Year - d2.Year));  

int months = ((M * 12) + Math.Abs((d1.Month - d2.Month)));

above code first get diffrence between two date.

then it multiply by 12. to get number of months and then at last it getting number of months between two date.


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend