Click or drag to resize

DateTimeOffsetExtensionsMonthsBetween Method

Returns the total number of months between two DateTimeOffset values.

Namespace: InnerDrive.Core
Assembly: InnerDrive.Core (in InnerDrive.Core.dll) Version: 5.0.8475.0
Syntax
C#
public static int MonthsBetween(
	this DateTimeOffset firstDate,
	DateTimeOffset secondDate
)

Parameters

firstDate  DateTimeOffset
The first DateTimeOffset value.
secondDate  DateTimeOffset
The second DateTimeOffset value.

Return Value

Int32
An Int32 containing the total number of months 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 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 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-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