Nepali DateNepali DateBikram Sambat Date Engine
Methods

Packagistdate->isSame()

Check whether two dates match across a specified granularity such as year, month, or day.

The isSame method compares the current NepaliDate instance with another date at a specified level of granularity, such as year, month, day, hour, or minute. It returns true if both dates match within that specific unit, simplifying range checks and calendar filters.


Import

use NepaliDateLibrary\NepaliDate;

Signature

public function isSame(NepaliDate $date, string $unit): bool;

Parameters

ParameterTypeRequiredDescription
$dateNepaliDateYesDate instance to compare with.
$unitstringYesGranularity: 'year', 'month', 'date', 'day'.

Return Value

  • Type: bool
  • Description: Returns true if the specified unit matches.

Example

use NepaliDateLibrary\NepaliDate;

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

// Same month and year
var_dump($d1->isSame($d2, 'month')); // true

// Different day
var_dump($d1->isSame($d2, 'date'));  // false

Advertisement

On this page