Methods
date.startOfYear()
Return a new NepaliDate instance set to the first day of the Bikram Sambat year on 1 Baisakh.
The startOfYear method returns a new NepaliDate instance set to 1 Baisakh, the first day of the Bikram Sambat calendar year. This is useful for year to date financial tracking and annual summary reports.
Import
import { NepaliDate } from "nepali-date-library";Signature
startOfYear(): NepaliDate;Parameters
This method does not take any parameters.
Return Value
- Type:
NepaliDate - Returns a new
NepaliDateset to 1st Baisakh of the current year. The original instance is not modified.
Examples
Navigating to Bikram Sambat New Year
import { NepaliDate } from "nepali-date-library";
// Any date within 2081 BS
const date = new NepaliDate("2081-08-15");
const newYear = date.startOfYear();
console.log(newYear.format("YYYY-MM-DD")); // "2081-01-01"
console.log(newYear.getMonth()); // 0 (Baisakh)
console.log(newYear.getDate()); // 1Year-to-Date Calculations
import { NepaliDate } from "nepali-date-library";
const today = new NepaliDate("2081-06-15");
const yearStart = today.startOfYear();
const daysElapsed = today.diff(yearStart, "day");
console.log(daysElapsed); // Number of days since start of the yearRelated
date.endOfYear(): Return the final day of the Bikram Sambat year.date.startOfMonth(): Return the first day of the current month.date.getYear(): Retrieve current Bikram Sambat year number.
Advertisement
date.endOfMonth()
Return a new NepaliDate instance set to the final day of the current Bikram Sambat month.
date.endOfYear()
Return a new NepaliDate instance set to the final day of the Bikram Sambat year on the last day of Chaitra.