Date Converter Guide
Comprehensive guide to converting dates between Gregorian and Bikram Sambat calendar systems using standalone helper functions.
The date converter utilities provide pure standalone functions for converting date strings directly between the Gregorian calendar and the Bikram Sambat calendar. These functions operate without creating full class instances, making them suitable for high throughput batch processing, database migrations, and backend service integration.
Available Functions
The library exports two primary conversion functions:
ADtoBS(adDate: str): Converts a Gregorian calendar date string to a Bikram Sambat date string.BStoAD(bsDate: str): Converts a Bikram Sambat date string to a Gregorian calendar date string.
Format Requirements
Both functions require strict ISO formatted date strings:
YYYY-MM-DD- Four digit year (
YYYY) - Two digit month with leading zero (
MM) - Two digit day with leading zero (
DD)
Comparison: Helper Functions vs NepaliDate Class
| Requirement | Use ADtoBS and BStoAD | Use NepaliDate Class |
|---|---|---|
| Fast string conversion | Recommended | Optional |
| Database pipelines and ETL | Recommended | Optional |
Date arithmetic (add_days, diff) | No | Recommended |
| Custom token formatting | No | Recommended |
| Calendar boundary calculations | No | Recommended |
| Fiscal year operations | No | Recommended |
Quick Example
from nepali_date_library import ADtoBS, BStoAD
# Gregorian to Bikram Sambat
bs = ADtoBS("2024-11-15")
print(bs) # "2081-07-30"
# Bikram Sambat to Gregorian
ad = BStoAD("2081-07-30")
print(ad) # "2024-11-15"Calendar Quarters
Explanation of standard Bikram Sambat calendar quarters compared to government fiscal trimesters.
ADtoBS()
Pure helper function to convert Gregorian calendar date strings into Bikram Sambat date strings.