How to get number of months between 2 dates c#
C#
class Program
{
static void Main(string[] args)
{
//First Date
DateTime firstDate = new DateTime(2017, 03, 03);
//Second Date
DateTime secondDate =new DateTime(2018, 06, 06); //DateTime.Now;
int months= MonthDiff(firstDate, secondDate);
Console.WriteLine("First Date :"+firstDate);
Console.WriteLine("Second Date :" + secondDate);
Console.WriteLine("Months :"+months);
Console.ReadLine();
}
public static int MonthDiff(DateTime d1, DateTime d2)
{
int m1;
int m2;
if(d1<d2)
{
m1 = (d2.Month - d1.Month);//for years
m2 = (d2.Year - d1.Year) * 12; //for months
}
else
{
m1 = (d1.Month - d2.Month);//for years
m2 = (d1.Year - d2.Year) * 12; //for months
}
return m1 + m2;
}
}
Also in C#:
- Title
- embed video to exe file with c#
- Category
- C#
- Title
- unity monobehaviour
- Category
- C#
- Title
- how to add a list to observablecollection in c#
- Category
- C#
- Title
- how to name GameObject in c#
- Category
- C#
- Title
- C# random.Next error
- Category
- C#
- Title
- c# array to list
- Category
- C#
- Title
- c# convert byte to char
- Category
- C#
- Title
- get random number c#
- Category
- C#
- Title
- linq foreach c#
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- how to make % posibility to spawn an object C# in unity
- Category
- C#
- Title
- webutility.urlencode space
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- c# random number between 0 and 1
- Category
- C#
- Title
- how to chagne rotation in unity
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- collision detector unity c# 2d
- Category
- C#
- Title
- get hash c#
- Category
- C#
- Title
- how to find the area of a circle
- Category
- C#
- Title
- get web config key value in c# razor view
- Category
- C#
- Title
- c# how to take from a float
- Category
- C#
- Title
- asking for user input integer c#
- Category
- C#
- Title
- C# for
- Category
- C#
- Title
- c# using get set methods
- Category
- C#
- Title
- array to list C
- Category
- C#
- Title
- gfortran: declare an array
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- unity rigidbody constraints
- Category
- C#
- Title
- unix time c#
- Category
- C#
- Title
- How can you learn C# on your own
- Category
- C#
- Title
- create line in unity
- Category
- C#
- Title
- c# get full URL of page
- Category
- C#
- Title
- unity check when clicked on object
- Category
- C#
- Title
- c# dictionaries
- Category
- C#
- Title
- set object to random color unity
- Category
- C#
- Title
- C# Unknown column 'FundAllocation' in 'field list
- Category
- C#
- Title
- asp.net render control to string
- Category
- C#
- Title
- c# get pc ip address
- Category
- C#
- Title
- bold caption latex
- Category
- C#
- Title
- how to create a variable in C#
- Category
- C#
- Title
- Rigidbody.addforce
- Category
- C#
- Title
- get random value from list c#
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- c# create dynamic object
- Category
- C#
- Title
- unity move character
- Category
- C#
- Title
- how do i foreach c#
- Category
- C#
- Title
- unity how to change rotation
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- c# how to check if two lists have same values
- Category
- C#
- Title
- c# find duplicates in list of strings
- Category
- C#
- Title
- Request.ServerVariables["HTTP_X_FORWARDED_FOR"] get only one ipaddress
- Category
- C#
- Title
- jump script unity 2d
- Category
- C#
- Title
- sum the digits in c#
- Category
- C#
- Title
- c# object list attribute to string
- Category
- C#
- Title
- .net 4.5 use tls 1.2
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- how to crouch in unity
- Category
- C#
- Title
- c# silent execute exe
- Category
- C#
- Title
- open udp socket c#
- Category
- C#
- Title
- c# check if type implements interface
- Category
- C#
- Title
- compose graphql query string in c#
- Category
- C#
- Title
- c# multiple catch exceptions
- Category
- C#
- Title
- split on uppercase c#
- Category
- C#
- Title
- list.addrange in c#
- Category
- C#
- Title
- Request.Form
- Category
- C#
- Title
- unity c# is not equal to
- Category
- C#
- Title
- unity simple fps controller
- Category
- C#
- Title
- c# discord bot
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- unity make a int arry with preset values
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- unity get decimal part of float
- Category
- C#
- Title
- socket in c#
- Category
- C#
- Title
- converting letter to ascii
- Category
- C#
- Title
- C# function return datareader
- Category
- C#
- Title
- c# index in select
- Category
- C#
- Title
- unity remove gameobject
- Category
- C#
- Title
- visual studio clear text script
- Category
- C#
- Title
- Assets\playermove.cs(30,37): error CS1003: Syntax error, ',' expected
- Category
- C#
- Title
- null coalescing operator c#
- Category
- C#
- Title
- clear combobox c#
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- c# format number with leading zeros
- Category
- C#
- Title
- defualtsize UWP c#
- Category
- C#
- Title
- parsing string to int without format exception c#
- Category
- C#
- Title
- eager loading vs lazy loading c#
- Category
- C#
- Title
- lista generica como parametro de un metodo en c#
- Category
- C#
- Title
- how to create a list in c# unity
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- roulette algorithm genetic algorithm
- Category
- C#
- Title
- c# compile into an exe
- Category
- C#
- Title
- iframe set html content c#
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- get user directory of file in c#
- Category
- C#
- Title
- combine two arraylist c#
- Category
- C#
- Title
- to list c#
- Category
- C#
- Title
- How do i destroy a prefab without the error?
- Category
- C#
- Title
- https request c#
- Category
- C#
- Title
- how to convert float to int c#
- Category
- C#
- Title
- unity how to get y value
- Category
- C#