Methods
date.daysInMonth()
Retrieve the total number of days in the current or specified Bikram Sambat month.
The daysInMonth method returns the total number of days present in the active month of the current NepaliDate instance, or for an explicitly provided year and month combination. Because Bikram Sambat month durations vary from 29 to 32 days depending on astronomical solar calculations, this method provides accurate month lengths.
Import
import { NepaliDate } from "nepali-date-library";Signature
daysInMonth(year?: number, month?: number): number;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
year | number | No | this.year | Bikram Sambat year (e.g. 2081). |
month | number | No | this.month | Zero-indexed month (0-11, where 0 is Baisakh and 11 is Chaitra). |
Return Value
- Type:
number - The number of days in the specified month (typically between 29 and 32 days).
Exceptions
Throws an Error if month is explicitly provided and is less than 0 or greater than 11:
"Invalid month index, must be between 0-11"Examples
Querying the Current Instance Month
import { NepaliDate } from "nepali-date-library";
// 2081 Baisakh
const date = new NepaliDate(2081, 0, 15);
console.log(date.daysInMonth()); // 31Querying an Arbitrary Year and Month
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate();
// Querying Jestha 2081 (month index 1)
const jesthaDays = date.daysInMonth(2081, 1);
console.log(jesthaDays); // 32
// Querying Chaitra 2080 (month index 11)
const chaitraDays = date.daysInMonth(2080, 11);
console.log(chaitraDays); // 30Related
date.getWeeksInMonth(): Compute number of calendar week rows.NepaliDate.getCalendarDays(): Generate month grid with padding.
Advertisement
date.isLeapYear()
Determine whether the current Bikram Sambat calendar year has three hundred sixty six or more days.
date.getWeeksInMonth()
Calculate the number of calendar week rows required to render the current month in a grid.