Nepali DateNepali DateBikram Sambat Date Engine
Methods

Packagistdate->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

ParameterTypeRequiredDescription
$yearsintYesNumber of years to advance or rewind.

Return Value

  • Type: NepaliDate
  • Description: Returns $this after mutation.

Example

use NepaliDateLibrary\NepaliDate;

$date = new NepaliDate('2075-01-01');
$date->addYears(5);
echo $date->format('YYYY-MM-DD'); // "2080-01-01"

Advertisement

On this page