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
use function NepaliDateLibrary\BStoAD;Signature
function BStoAD(string $bsDate): string;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$bsDate | string | Yes | Bikram Sambat date string formatted strictly as YYYY-MM-DD. |
Return Value
- Type:
string - Format:
YYYY-MM-DDrepresenting the equivalent Gregorian calendar date.
Exceptions
| Exception Class | Trigger Condition |
|---|---|
InvalidArgumentException | Thrown if input does not match format YYYY-MM-DD or has out of range year, month, or day values. |
RuntimeException | Thrown if the conversion calculation fails unexpectedly. |
Examples
Basic Conversion
use function NepaliDateLibrary\BStoAD;
$gregorianDate = BStoAD('2080-01-01');
echo $gregorianDate; // "2023-04-14"Storing in SQL Databases
$userInputBs = '2081-07-15';
$databaseAdDate = BStoAD($userInputBs);
echo $databaseAdDate; // "2024-10-31"Related
ADtoBS(): Convert Gregorian date strings to Bikram Sambat.date->getEnglishDate(): Retrieve a native PHP DateTimeImmutable object.
Advertisement
ADtoBS()
Pure helper function to convert Gregorian calendar date strings into Bikram Sambat date strings.
Constants::$NEPALI_DATE_MAP
Historical calendar mapping table storing verified day counts for every Bikram Sambat month between 1976 and 2100 BS.