Methods
date.addDays()
Add or subtract a specified number of days to a NepaliDate instance with automatic month and year rollover.
The addDays method modifies the current NepaliDate instance by adding or subtracting a given integer number of days. It automatically handles variable Bikram Sambat month day counts, transitions across month boundaries, and advances or decrements the year when needed.
Import
import { NepaliDate } from "nepali-date-library";Signature
addDays(days: number): NepaliDate;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
days | number | Yes | Integer number of days to add (positive) or subtract (negative). |
Return Value
- Type:
NepaliDate - Returns a new
NepaliDateinstance with the specified days added or subtracted. The original instance is not modified.
Examples
Adding Days Across Month Boundaries
import { NepaliDate } from "nepali-date-library";
// 2081 Baisakh 25 (Baisakh 2081 has 31 days)
const date = new NepaliDate("2081-01-25");
const next = date.addDays(10);
console.log(next.format("YYYY-MM-DD")); // "2081-02-04" (4 Jestha)Subtracting Days Across Year Boundaries
import { NepaliDate } from "nepali-date-library";
// 2081 Baisakh 02
const date = new NepaliDate("2081-01-02");
const prev = date.addDays(-5);
console.log(prev.format("YYYY-MM-DD")); // "2080-12-28" (28 Chaitra 2080)Method Chaining
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2081-01-01")
.addDays(15)
.addDays(5);
console.log(date.format("YYYY-MM-DD")); // "2081-01-21"Related
date.addMonths(): Add or subtract whole months.date.diff(): Calculate the difference between two dates in days.
Advertisement
date.parse()
Parse a formatted Bikram Sambat date string and update the current date instance in place.
date.addMonths()
Add or subtract months to a NepaliDate instance while adjusting for variable month lengths.