Avatar of pzozulka
pzozulka
 asked on

C# DateDiff in Months

I need to get the difference in months between two dates.

In SQL, this is what I need:
select DATEDIFF(MONTH, '11/1/2014', DATEADD(mm, DATEDIFF(mm, 0, '12/31/2014') + 1, 0)) 

Open in new window


The above date difference should be 2 months.
Difference between 12/10/2014 and 12/20/2014 = 1 month.
Difference between 11/1/2012 and 12/31/2014 = 26 months.

How do I do the same in C#?
C#Microsoft SQL Server.NET Programming

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Vel Eous

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes