Nepali DateNepali DateBikram Sambat Date Engine
Methods

date.setMonth()

Set the Bikram Sambat month index on a NepaliDate instance with automatic day clamping.

The setMonth method updates the Bikram Sambat month for the current NepaliDate instance using a zero based month index from 0 for Baisakh to 11 for Chaitra. If the current day exceeds the total days in the destination month, the day is automatically clamped to the final valid day of that month.


Import

import { NepaliDate } from "nepali-date-library";

Signature

setMonth(month: number): void;

Parameters

ParameterTypeRequiredDescription
monthnumberYes0-indexed month integer (0 for Baisakh to 11 for Chaitra).

Return Value

  • Type: void
  • Mutates the current NepaliDate instance in place.

Exceptions

Error MessageTrigger Condition
Invalid nepali month must be between 1 - 12Thrown if month is outside 0 to 11.

Example

import { NepaliDate } from "nepali-date-library";

// 2081 Baisakh 15 (month index 0)
const date = new NepaliDate("2081-01-15");

// Shift to Shrawan (month index 3)
date.setMonth(3);
console.log(date.format("YYYY-MM-DD")); // "2081-04-15"

Advertisement

On this page