Methods
date->addYears()
Add or subtract years to a NepaliDate instance while preserving month and day values.
The addYears method adds or subtracts a specified number of years to the current NepaliDate instance. It recalculates the underlying timestamp while retaining the month and day coordinates, adjusting the day number if the target year has fewer days in that specific month.
Import
use NepaliDateLibrary\NepaliDate;Signature
public function addYears(int $years): self;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$years | int | Yes | Number of years to advance or rewind. |
Return Value
- Type:
NepaliDate - Description: Returns
$thisafter mutation.
Example
use NepaliDateLibrary\NepaliDate;
$date = new NepaliDate('2075-01-01');
$date->addYears(5);
echo $date->format('YYYY-MM-DD'); // "2080-01-01"Related
date->addMonths(): Add or subtract months.date->diff(): Difference between two dates.
Advertisement
date->addMonths()
Add or subtract months to a NepaliDate instance while adjusting for variable month lengths.
date->diff()
Calculate the chronological difference between two NepaliDate instances in specific time units.