Jakew
Consulting, hacking, and motorcycles

Get number of months between two dates

Friday, 16 October 2009 08:00 by jakew

I need to get the number of months between two dates.  Unfortunately the timespan object does not provide that.  It is easy enough to calculate, but even better: use VB!  Add a reference to Microsoft.VisualBasic in your project and then in your code add:

DateAndTime.DateDiff(DateInterval.Month, startDate, endDate
                     ,FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1);

 

The problem you’ll run in to is the last two parameters.  In VB they are not required, but you have no way to not send them in C#.  In my case the parameters I chose will work well enough.  YMMV.

Categories:   Tech
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed