Answer by Adam Ralph for Difference in months between two dates
Assuming the day of the month is irrelevant (i.e. the diff between 2011.1.1 and 2010.12.31 is 1), with date1 > date2 giving a positive value and date2 > date1 a negative value((date1.Year -...
View ArticleDifference in months between two dates
How to calculate the difference in months between two dates in C#?Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. The...
View ArticleAnswer by Miguel for Difference in months between two dates
In case you just care about the month and year and want to touch both dates (for example you want to go thru JAN/2021 to AGO/2022) you can use this:int numberOfMonths= (Year2 > Year1 ? ( Year2 -...
View ArticleAnswer by Adam Janovec for Difference in months between two dates
one line solutionFor first, check if both dates are in current year, if not get months of whole years and then add months from start and end year.DateTime dateFrom = new DateTime(2019, 2, 1);DateTime...
View ArticleAnswer by Dan Hilderbrand for Difference in months between two dates
I was working on a project that only delt in years and months. Here is a solution that may help./// <summary>/// Get the total months between two date. This will count whole months and not care...
View ArticleAnswer by EgoPingvina for Difference in months between two dates
Someone must have done it))The extension method returns the number of full months between the given dates. No matter in what order the dates are received, a natural number will always be returned.No...
View Article