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
use function NepaliDateLibrary\ADtoBS;Signature
function ADtoBS(string $adDate): string;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$adDate | string | Yes | Gregorian date string formatted strictly as YYYY-MM-DD. |
Return Value
- Type:
string - Format:
YYYY-MM-DDrepresenting the corresponding Bikram Sambat date.
Exceptions
| Exception Class | Trigger Condition |
|---|---|
InvalidArgumentException | Thrown if input does not match format YYYY-MM-DD or contains invalid calendar dates. |
RuntimeException | Thrown if the date falls outside the supported historical range. |
Examples
Basic Conversion
use function NepaliDateLibrary\ADtoBS;
$nepaliDate = ADtoBS('2023-04-14');
echo $nepaliDate; // "2080-01-01"Processing Database Records
$records = [
['id' => 1, 'created_at' => '2024-01-01'],
['id' => 2, 'created_at' => '2024-07-15'],
];
foreach ($records as &$item) {
$item['created_at_bs'] = ADtoBS($item['created_at']);
}Related
BStoAD(): Reverse conversion from Bikram Sambat to Gregorian.NepaliDate Class: Full date manipulation and arithmetic object.
Advertisement
Date Converter Guide
Comprehensive guide to converting dates between Gregorian and Bikram Sambat calendar systems using standalone helper functions.
BStoAD()
Pure helper function to convert Bikram Sambat date strings into Gregorian calendar date strings.