Nepali DateNepali DateBikram Sambat Date Engine
Date Converter

PackagistADtoBS()

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

ParameterTypeRequiredDescription
$adDatestringYesGregorian date string formatted strictly as YYYY-MM-DD.

Return Value

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

Exceptions

Exception ClassTrigger Condition
InvalidArgumentExceptionThrown if input does not match format YYYY-MM-DD or contains invalid calendar dates.
RuntimeExceptionThrown 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']);
}

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

On this page