Methods
date->addMonths()
Add or subtract months to a NepaliDate instance while adjusting for variable month lengths.
The addMonths method advances or rewinds the current NepaliDate instance by a specified number of months. If the current day of the month exceeds the total days available in the destination month, the method automatically clamps the day to the final valid day of that month to ensure calendar consistency.
Import
use NepaliDateLibrary\NepaliDate;Signature
public function addMonths(int $months): self;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$months | int | Yes | Positive or negative integer of months to add. |
Return Value
- Type:
NepaliDate - Description: Returns
$thisafter mutation.
Example
use NepaliDateLibrary\NepaliDate;
$date = new NepaliDate('2081-01-15');
$date->addMonths(6);
echo $date->format('YYYY-MM-DD'); // "2081-07-15"Related
date->addYears(): Add or subtract years.date->addDays(): Add or subtract days.
Advertisement
date->addDays()
Add or subtract a specified number of days to a NepaliDate instance with automatic month and year rollover.
date->addYears()
Add or subtract years to a NepaliDate instance while preserving month and day values.