DateTimeExtensionsYearsBetween Method

Returns the total number of years between this DateTime and another DateTime.

Definition

Namespace: InnerDrive.Core
Assembly: InnerDrive.Core (in InnerDrive.Core.dll) Version: 5.2.9017.0
C#
public static int YearsBetween(
	this DateTime firstDate,
	DateTime secondDate
)

Parameters

firstDate  DateTime
This DateTime value.
secondDate  DateTime
The second DateTime value.

Return Value

Int32
An Int32 containing the total number of years between firstDate and secondDate.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type DateTime. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

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 dateSecond dateResult
2001-01-151999-01-14-2
2001-01-151999-01-15-1
2001-01-152000-01-15-1
2001-01-152000-01-160
2001-01-152001-01-150
2001-01-152002-01-140
2001-01-152002-01-151
2001-01-152006-01-014
2001-01-152006-01-144
2001-01-152006-01-155
2001-01-152006-12-315
2001-01-152007-01-145

Example

C#
var firstDate = new DateTime(2000, 1, 1);
var secondDate = new DateTime(2010, 1, 1);
? firstDate.MonthsBetween(secondDate);

// Result: 10

See Also