Nepali DateNepali DateBikram Sambat Date Engine
Date Converter

BStoAD()

Pure helper function to convert Bikram Sambat date strings into Gregorian calendar date strings.

The BStoAD function converts a Bikram Sambat date string into its equivalent Gregorian calendar date string. It validates the input Nepali date against verified historical calendar maps and returns a formatted Gregorian date string suitable for storage in standard SQL databases or transmission over web APIs.


Import

import { BStoAD } from "nepali-date-library";
const { BStoAD } = require("nepali-date-library");

Signature

function BStoAD(bsDate: string): string;

Parameters

ParameterTypeRequiredDescription
bsDatestringYesBikram Sambat date string formatted strictly as YYYY-MM-DD.

Return Value

  • Type: string
  • Format: YYYY-MM-DD representing the corresponding Gregorian date in UTC.

Exceptions

Error MessageTrigger Condition
Invalid date format. Expected format: YYYY-MM-DDThrown if bsDate fails the format regex ^\d{4}-\d{2}-\d{2}$.
Nepal year out of rangeThrown if year is earlier than 1976 BS or later than 2100 BS.
Invalid nepali month must be between 1 - 12Thrown if month component is not within 1 to 12.
Invalid nepali date must be between 1 - <max> in <year> <month>Thrown if the day exceeds the verified days for that specific month and year.
DateConversionError: Failed to convert BS to ADWrapped error for conversion failures.

Examples

Basic Conversion

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

const adDate = BStoAD("2081-07-15");
console.log(adDate); // "2024-10-31"

Converting Month with 32 Days

Bikram Sambat summer months can contain 32 days. BStoAD validates the exact ephemeris for that year:

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

// Jestha 32, 2081
const adDate = BStoAD("2081-02-32");
console.log(adDate); // "2024-06-14"

Database Persistence Pattern

Convert user-entered Bikram Sambat dates to standard ISO-8601 strings prior to storing in SQL or NoSQL databases:

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

interface UserRegistrationInput {
  fullName: string;
  birthDateBS: string; // e.g. "2055-04-12"
}

function prepareUserForStorage(input: UserRegistrationInput) {
  return {
    fullName: input.fullName,
    birthDateBS: input.birthDateBS,
    birthDateAD: BStoAD(input.birthDateBS), // "1998-07-27"
  };
}

Advertisement

On this page