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
from nepali_date_library import BStoADSignature
def BStoAD(bsDate: str) -> str:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
bsDate | str | Yes | Bikram Sambat date string formatted strictly as YYYY-MM-DD. |
Return Value
- Type:
str - Format:
YYYY-MM-DDrepresenting the equivalent Gregorian calendar date.
Exceptions
| Error Message | Trigger Condition |
|---|---|
Invalid date format. Expected format: YYYY-MM-DD | Raised if input string fails the regex validation ^\d{4}-\d{2}-\d{2}$. |
Nepal year out of range | Raised if the year is earlier than 1976 BS or later than 2100 BS. |
Invalid Nepali month | Raised if the month number is not between 1 and 12. |
Invalid Nepali date | Raised if the day number exceeds the actual days in that specific Nepali month. |
Examples
Basic Conversion
from nepali_date_library import BStoAD
gregorian_date = BStoAD("2080-01-01")
print(gregorian_date) # "2023-04-14"Storing in SQL Databases
user_input_bs = "2081-07-15"
database_ad_date = BStoAD(user_input_bs)
print(database_ad_date) # "2024-10-31"Related
ADtoBS(): Convert Gregorian date strings to Bikram Sambat.date.get_english_date(): Retrieve a native Python datetime object.
Advertisement
ADtoBS()
Pure helper function to convert Gregorian calendar date strings into Bikram Sambat date strings.
nepali_date_map
Historical calendar mapping table storing verified day counts for every Bikram Sambat month between 1976 and 2100 BS.