Methods
date->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
| Parameter | Type | Required | Description |
|---|---|---|---|
$date | NepaliDate | Yes | Date instance to compare with. |
$unit | string | Yes | Granularity: 'year', 'month', 'date', 'day'. |
Return Value
- Type:
bool - Description: Returns
trueif 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')); // falseRelated
date->isEqual(): Compare full date equality.date->diff(): Quantitative difference.
Advertisement
date->isEqual()
Check whether two date instances share the exact same calendar date coordinates regardless of time.
date->isValidInstance()
Validate whether the current NepaliDate instance represents a legitimate calendar date within supported bounds.