Nepali DateNepali DateBikram Sambat Date Engine
Methods

date.is_same()

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

The is_same 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

from nepali_date_library import NepaliDate

Signature

def is_same(self, date: NepaliDate, unit: str) -> bool:

Parameters

ParameterTypeRequiredDescription
dateNepaliDateYesDate instance to compare with.
unitstrYesGranularity: "year", "month", "date", "day".

Return Value

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

Example

from nepali_date_library import NepaliDate

d1 = NepaliDate("2081-07-05")
d2 = NepaliDate("2081-07-20")

# Same month and year
print(d1.is_same(d2, "month")) # True

# Different day
print(d1.is_same(d2, "date"))  # False

Advertisement

On this page