Horje
get list of months and year between two dates c# Code Example
total months between two dates c#
((date1.Year - date2.Year) * 12) + date1.Month - date2.Month
get list of months and year between two dates c#
public static IEnumerable<(string Month, int Year)> MonthsBetween(
        DateTime startDate,
        DateTime endDate)
{
    DateTime iterator;
    DateTime limit;

    if (endDate > startDate)
    {
        iterator = new DateTime(startDate.Year, startDate.Month, 1);
        limit = endDate;
    }
    else
    {
        iterator = new DateTime(endDate.Year, endDate.Month, 1);
        limit = startDate;
    }

    var dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat;
    while (iterator <= limit)
    {
        yield return (
            dateTimeFormat.GetMonthName(iterator.Month), 
            iterator.Year
        );

       iterator = iterator.AddMonths(1);
    }
}




Csharp

Related
how to exit winforms application and shutdown pc in c# Code Example how to exit winforms application and shutdown pc in c# Code Example
c# list object Code Example c# list object Code Example
how to create a variab;e in c# Code Example how to create a variab;e in c# Code Example
c# split include separators Code Example c# split include separators Code Example
declare prop array c# Code Example declare prop array c# Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12