Nepali DateNepali DateBikram Sambat Date Engine
Date Converter

ADtoBS()

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

The ADtoBS function performs direct mathematical conversion of a Gregorian date string into its corresponding Bikram Sambat date string. It accepts standard date formats and returns the converted Nepali date, handling month day variations and leap year calculations automatically without external dependencies.


Import

from nepali_date_library import ADtoBS

Signature

def ADtoBS(adDate: str) -> str:

Parameters

ParameterTypeRequiredDescription
adDatestrYesGregorian date string formatted strictly as YYYY-MM-DD.

Return Value

  • Type: str
  • Format: YYYY-MM-DD representing the corresponding Bikram Sambat date.

Exceptions

Error MessageTrigger Condition
Invalid date format. Expected format: YYYY-MM-DDRaised if input does not strictly match the four digit year and two digit month day pattern.
Invalid date input '<adDate>'Raised if date components cannot be parsed into valid Gregorian dates.
Fail to convert AD to BSRaised if the date falls outside the supported historical range.

Examples

Basic Conversion

from nepali_date_library import ADtoBS

nepali_date = ADtoBS("2023-04-14")
print(nepali_date) # "2080-01-01"

Processing Data Records

records = [
    {"id": 1, "created_at": "2024-01-01"},
    {"id": 2, "created_at": "2024-07-15"},
]

for item in records:
    item["created_at_bs"] = ADtoBS(item["created_at"])

  • BStoAD(): Reverse conversion from Bikram Sambat to Gregorian.
  • NepaliDate Class: Full date manipulation and arithmetic object.
Advertisement

On this page