DateTimeOffsetExtensionsYearsBetween Method

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

Definition

Namespace: InnerDrive.Core
Assembly: InnerDrive.Core (in InnerDrive.Core.dll) Version: 5.3.9666.0
C#
public static int YearsBetween(
	this DateTimeOffset dateTimeOffset,
	DateTimeOffset secondDate
)

Parameters

dateTimeOffset  DateTimeOffset
This DateTimeOffset.
secondDate  DateTimeOffset
The second DateTimeOffset value.

Return Value

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

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type DateTimeOffset. 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 dateTimeOffset and secondDate may be specified in any order. If dateTimeOffset is less than or equal to secondDate, a positive number will be returned. If dateTimeOffset 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 DateTimeOffset(2012, 1, 1, 0, 0, 0, TimeSpan.Zero);
var secondDate = new DateTimeOffset(2010, 1, 1, 0, 0, 0, TimeSpan.Zero);
? firstDate.YearsBetween(secondDate);

// Result: -2

See Also