Skip to content

Simple C# extension methods to calculate the difference in months between two dates

License

Notifications You must be signed in to change notification settings

markwhitaker/MonthDiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MonthDiff

A very simple pair of extension methods on DateTime and DateTimeOffset to calculate the difference in months between two dates.

I wanted it to work exactly like a TotalMonths property on TimeSpan would work, i.e. return the count of complete months between two dates, ignoring any partial months. Because it's based on DateTime.AddMonths() it respects different month lengths and returns what a human would understand as a period of months. Unfortunately it can't be implemented as an extension method on TimeSpan because that doesn't retain knowledge of the actual dates used, and for months they're important.

Originally posted at StackOverflow.

About

Simple C# extension methods to calculate the difference in months between two dates

Topics

Resources

License

Stars

Watchers

Forks

Languages