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 NepaliDateSignature
def diff(self, date: NepaliDate, unit: str) -> int:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
date | NepaliDate | Yes | Target date instance to compare against. |
unit | str | Yes | Measurement 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}") # 19Related
date.is_before(): Check chronological order.date.is_after(): Check chronological order.
Advertisement
date.add_years()
Add or subtract years to a NepaliDate instance while preserving month and day values.
date.start_of_day()
Return a new NepaliDate instance set to the first moment of the current day at midnight.