The OpenD Programming Language

SysTime.diffMonths

Returns the difference between the two SysTimes in months.

To get the difference in years, subtract the year property of two SysTimes. To get the difference in days or weeks, subtract the SysTimes themselves and use the core.time.Duration that results. Because converting between months and smaller units requires a specific date (which core.time.Durations don't have), getting the difference in months requires some math using both the year and month properties, so this is a convenience function for getting the difference in months.

Note that the number of days in the months or how far into the month either date is is irrelevant. It is the difference in the month property combined with the difference in years * 12. So, for instance, December 31st and January 1st are one month apart just as December 1st and January 31st are one month apart.

struct SysTime
@safe const nothrow scope
int
diffMonths
(
scope SysTime rhs
)

Parameters

rhs SysTime

The SysTime to subtract from this one.

Examples

import core.time;
import std.datetime.date : Date;

assert(SysTime(Date(1999, 2, 1)).diffMonths(
           SysTime(Date(1999, 1, 31))) == 1);

assert(SysTime(Date(1999, 1, 31)).diffMonths(
           SysTime(Date(1999, 2, 1))) == -1);

assert(SysTime(Date(1999, 3, 1)).diffMonths(
           SysTime(Date(1999, 1, 1))) == 2);

assert(SysTime(Date(1999, 1, 1)).diffMonths(
           SysTime(Date(1999, 3, 31))) == -2);

Meta