Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

total months between two dates c#

((date1.Year - date2.Year) * 12) + date1.Month - date2.Month
Comment

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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: reference to gameobject in different scene unity 
Csharp :: ex: c# last item in array 
Csharp :: c# extension 
Csharp :: Transpose Matrix CSharp 
Csharp :: linq syntax 
Csharp :: longest palindromic substring 
Csharp :: truncate c# 
Csharp :: link list in c# 
Csharp :: binary tree c# 
Csharp :: c# convert datetime to timespan 
Csharp :: how to add a ddos api to a c# console app 
Csharp :: c# quick "is" "as" 
Csharp :: C# ToCsv Extension Method 
Csharp :: json serialize object capitalization config 
Csharp :: rename join ta le in many to many 
Csharp :: c# check multiple variables for null 
Csharp :: singleton pattern c# stack overflow 
Csharp :: how to make enemy killed by bullet unity2D 
Csharp :: transform.lookat 2d 
Csharp :: Get single listView SelectedItem 
Csharp :: Make Enemy follow and rotate towards target in Unity 
Csharp :: how to populate a collection c# 
Csharp :: is list sequential C# 
Csharp :: firefoxoptions setpreference to trust certificates 
Csharp :: [1], [2], [3] 
Csharp :: asp net identity extend relationship 
Csharp :: c# language 
Csharp :: How to fill text with 2 different color/texture 
Csharp :: discord bot c# interrupt CollectReactionsAsync 
Csharp :: unity 2d top down movement script 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =