Returns the Day that comes the specified
numberOfMonths before this Day in the calendar.
Namespace: DegreeDays.TimeAssembly: DegreeDays (in DegreeDays.dll) Version: 1.4
Syntax public Day MinusMonths(
int numberOfMonths
)
Public Function MinusMonths (
numberOfMonths As Integer
) As Day
Parameters
- numberOfMonths Int32
- The number of months to subtract from this
Day. Can be positive (to go backwards in time), zero,
or negative (to go forwards in time).
Return Value
DayA
Day representing the result of the operation.
Exceptions Exception | Condition |
---|
OverflowException | In the unlikely event of this method
requiring a Day with a year less than 1 or
greater than 9999. |
Remarks
This will happily cross the borders between years, and it will always
ensure that the returned result is a valid Day, unless it is
outside the range allowed by Day (0001-01-01 to 9999-12-31
inclusive), in which case it will throw an
OverflowException.
The DayOfMonth of the returned Day will be the
same as that of this Day when possible, but sometimes it
will have to be reduced, to fit within the constraints of the resulting
month. For example:
- 2020-05-31 minus 1 month would give a result of 2020-04-30 (because
April only has 30 days, 2020-04-31 would not be a valid date, so this
will return 2020-04-30 instead).
- 2020-04-30 minus 2 months would give a result of 2020-02-29 (the last
day in February 2020, which has 29 days instead of 28 because 2020 is a
leap year).
However, the DayOfMonth will only change when absolutely
necessary, for example:
- 2020-03-31 minus 2 months will give a result of 2020-01-31. It does
not matter that February 2020 had only 29 days because we are subtracting
2 months, not 1.
- 2020-02-29 minus 48 months (i.e. 4 years) will give a result of
2016-02-29. 2020 and 2016 are both leap years, it does not matter that
the years in between are not.
Day is immutable, so calling this method will not change
this Day.
See Also