PhoenixmlDb.Core

YearMonthDuration

Represents an xs:yearMonthDuration value as a count of months, implementing correct XML Schema semantics for month-based date arithmetic.

#YearMonthDuration

Namespace: PhoenixmlDb.Xdm

Represents an

xs:yearMonthDuration

value as a count of months, implementing correct XML Schema semantics for month-based date arithmetic.

Unlike TimeSpan, which only supports fixed-length durations, this type correctly handles variable-length months. For example, adding 1 month to January 31 yields February 28/29, which cannot be expressed as a fixed number of days.

The canonical lexical form is PnYnM (e.g., P1Y6M for 18 months). Negative durations are prefixed with - (e.g., -P3M).

#Example

csharp
var dur = YearMonthDuration.Parse("P1Y6M");
Console.WriteLine(dur.TotalMonths); // 18
Console.WriteLine(dur.Years);       // 1
Console.WriteLine(dur.Months);      // 6
                                  

#Constructors

##ctor(Int32)

Represents an

xs:yearMonthDuration

value as a count of months, implementing correct XML Schema semantics for month-based date arithmetic.

Parameters:

  • TotalMonths — The total number of months (negative for negative durations).

Unlike TimeSpan, which only supports fixed-length durations, this type correctly handles variable-length months. For example, adding 1 month to January 31 yields February 28/29, which cannot be expressed as a fixed number of days.

The canonical lexical form is PnYnM (e.g., P1Y6M for 18 months). Negative durations are prefixed with - (e.g., -P3M).

Example:

csharp
var dur = YearMonthDuration.Parse("P1Y6M");
Console.WriteLine(dur.TotalMonths); // 18
Console.WriteLine(dur.Years);       // 1
Console.WriteLine(dur.Months);      // 6
                                  

#Properties

Name Description
TotalMonths The total number of months (negative for negative durations).