Link to home
Start Free TrialLog in
Avatar of joan2006
joan2006

asked on

calculate number of months between two date

I am trying to calculate the number of months between two dates in c#.
I have two dates in a c# string.
At first i was calculating Mat.Abs(DateTime.Parse(txtStartDt.Value).Month - DateTime.Parse(txtEndDt.Value).Month))+ 1

Then i realized that i may have values where the years differ eg. 2007 - 2009 the code i have above doesnt account for that.  

What would be the best solution/algorithm to get the correct number of months from two dates?
SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry type O in this line.

1. Add a DLL reference Microsoft.VisualBasic to the application
   found in the .Net Tab of the Add Reference dialog box.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial