DateTimeExtensionsYearsBetween Method
The parameters
firstDate and
secondDate
may be specified in any order. If
firstDate is
less than or equal to
secondDate, a positive number will be returned.
If
firstDate is larger, a negative number will be returned.
First date | Second date | Result |
---|
2001-01-15 | 1999-01-14 | -2 |
2001-01-15 | 1999-01-15 | -1 |
2001-01-15 | 2000-01-15 | -1 |
2001-01-15 | 2000-01-16 | 0 |
2001-01-15 | 2001-01-15 | 0 |
2001-01-15 | 2002-01-14 | 0 |
2001-01-15 | 2002-01-15 | 1 |
2001-01-15 | 2006-01-01 | 4 |
2001-01-15 | 2006-01-14 | 4 |
2001-01-15 | 2006-01-15 | 5 |
2001-01-15 | 2006-12-31 | 5 |
2001-01-15 | 2007-01-14 | 5 |
var firstDate = new DateTime(2000, 1, 1);
var secondDate = new DateTime(2010, 1, 1);
? firstDate.MonthsBetween(secondDate);
// Result: 10