Nepali DateNepali DateBikram Sambat Date Engine
Methods

date.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

from nepali_date_library import NepaliDate

Signature

def diff(self, date: NepaliDate, unit: str) -> int:

Parameters

ParameterTypeRequiredDescription
dateNepaliDateYesTarget date instance to compare against.
unitstrYesMeasurement unit: "days", "months", "years", "hours", "minutes", "seconds".

Return Value

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

Example

from nepali_date_library import NepaliDate

d1 = NepaliDate("2081-01-01")
d2 = NepaliDate("2081-01-20")

days_diff = d2.diff(d1, "days")
print(f"Difference in days: {days_diff}") # 19

Advertisement

On this page