Nepali DateNepali DateBikram Sambat Date Engine
Date Converter

PackagistDate 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 in the NepaliDateLibrary namespace:


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

RequirementUse ADtoBS and BStoADUse NepaliDate Class
Fast string conversionRecommendedOptional
Database pipelines and ETLRecommendedOptional
Date arithmetic (addDays, diff)NoRecommended
Custom token formattingNoRecommended
Calendar boundary calculationsNoRecommended
Fiscal year operationsNoRecommended

Quick Example

use function NepaliDateLibrary\ADtoBS;
use function NepaliDateLibrary\BStoAD;

// Gregorian to Bikram Sambat
$bs = ADtoBS('2024-11-15');
echo $bs; // "2081-07-30"

// Bikram Sambat to Gregorian
$ad = BStoAD('2081-07-30');
echo $ad; // "2024-11-15"
Advertisement

On this page