Nepali DateNepali DateBikram Sambat Date Engine
Methods

Packagistdate->diff()

Calculate the chronological difference between two NepaliDate instances in specific time units.

The diff method calculates the elapsed time duration between the current NepaliDate instance and another date object. It can return the difference in days, months, years, hours, minutes, seconds, or milliseconds, making it suitable for calculating age, tenure, or interval durations.


Import

use NepaliDateLibrary\NepaliDate;

Signature

public function diff(NepaliDate $date, string $unit): int;

Parameters

ParameterTypeRequiredDescription
$dateNepaliDateYesTarget date instance to compare against.
$unitstringYesMeasurement unit: 'days', 'months', 'years', 'hours', 'minutes', 'seconds'.

Return Value

  • Type: int
  • Description: Integer difference count in the specified unit.

Example

use NepaliDateLibrary\NepaliDate;

$d1 = new NepaliDate('2081-01-01');
$d2 = new NepaliDate('2081-01-20');

$daysDiff = $d2->diff($d1, 'days');
echo "Difference in days: {$daysDiff}"; // 19

Advertisement

On this page