Quantcast
Channel: Difference in months between two dates - Stack Overflow
Browsing index pages (48 articles)
↧

Answer by Jean-David Lanz for Difference in months between two dates

Um, actually, the OP asked for something like VB's DateDiff(). It turns out that that function works very simply for months:((LastDate.Year - FirstDate.Year) * 12) + LastDate.Month -...

View Article


Answer by kostasandre for Difference in months between two dates

If you're still looking for a proper solution to ensure that two dates fall within a given maximum number of months—including variations in month lengths (such as February)—I’ve come up with the...

View Article


Answer 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

Answer 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 Article

Answer 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 Article


Answer 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 Article

Difference 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 Article

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 Article


Answer by Cheng Chen for Difference in months between two dates

I checked the usage of this method in VB.NET via MSDN and it seems that it has a lot of usages. There is no such a built-in method in C#. (Even it's not a good idea) you can call VB's in C#.Add...

View Article


Answer by Mohammad Ali for Difference in months between two dates

Public Class ClassDateOperation Private prop_DifferenceInDay As Integer Private prop_DifferenceInMonth As Integer Private prop_DifferenceInYear As Integer Public Function DayMonthYearFromTwoDate(ByVal...

View Article

Answer by Mongus Pong for Difference in months between two dates

You could do if ( date1.AddMonths(x) > date2 )

View Article

Answer by Kirk Woll for Difference in months between two dates

Here is a comprehensive solution to return a DateTimeSpan, similar to a TimeSpan, except that it includes all the date components in addition to the time components.Usage:void Main(){ DateTime...

View Article

Answer by Guillaume86 for Difference in months between two dates

If you want the exact number of full months, always positive (2000-01-15, 2000-02-14 returns 0), considering a full month is when you reach the same day the next month (something like the age...

View Article


Answer by Wayne for Difference in months between two dates

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...

View Article

Answer by Tom for Difference in months between two dates

To be able to calculate the difference between 2 dates in months is a perfectly logical thing to do, and is needed in many business applications. The several coders here who have provided comments such...

View Article


Answer by Firnas for Difference in months between two dates

You can have a function something like this.For Example, from 2012/12/27 to 2012/12/29 becomes 3 days. Likewise, from 2012/12/15 to 2013/01/15 becomes 2 months, because up to 2013/01/14 it's 1 month....

View Article

Answer by Sukanta for Difference in months between two dates

public static int PayableMonthsInDuration(DateTime StartDate, DateTime EndDate){ int sy = StartDate.Year; int sm = StartDate.Month; int count = 0; do { count++;if ((sy == EndDate.Year) && (sm...

View Article


Answer by Elmer for Difference in months between two dates

This worked for what I needed it for. The day of month didn't matter in my case because it always happens to be the last day of the month.public static int MonthDiff(DateTime d1, DateTime d2){ int...

View Article

Answer by reza akhlaghi for Difference in months between two dates

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;...

View Article

Answer by Patrice Calvé for Difference in months between two dates

There's 3 cases: same year, previous year and other years.If the day of the month does not matter...public int GetTotalNumberOfMonths(DateTime start, DateTime end){ // work with dates in the right...

View Article
Browsing index pages (48 articles)


Latest Images