DateTimeOffsetExtensionsMonthsBetween Method

Returns the total number of months between two DateTimeOffset values.

Definition

Namespace: InnerDrive.Core
Assembly: InnerDrive.Core (in InnerDrive.Core.dll) Version: 5.3.9666.0
C#
public static int MonthsBetween(
	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 months 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

Only the Month portions of the values are considered.

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-012001-03-312
2001-01-312001-03-012
2001-01-012001-01-310
2001-01-312001-01-010
2001-01-012000-12-31-1

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.MonthsBetween(secondDate);

// Result: -24

See Also