ashbink / nepali-miti
A standalone PHP package for converting BS to AD and vice versa.
Requires
- php: ^8.0
README
A blazing fast, lightweight, and framework-agnostic PHP package to convert Nepali Date (Bikram Sambat - BS) to English Date (Anno Domini - AD) and vice versa.
Works perfectly with pure Core PHP, Laravel, CodeIgniter, Symfony, and WordPress!
🚀 Features
- Framework-Agnostic: No framework dependencies. Works anywhere PHP runs.
- Lightning Fast: Zero database queries. Everything runs in-memory.
- Multiple Date Formats: Seamlessly parse and format dates in multiple standard formats.
- Textual Dates: Support for translating dates into text (e.g.,
2082 कार्तिक 25or2026 August 20). - Zero Setup: No configuration required.
- 100% Accurate BS to AD conversion.
- 100% Accurate AD to BS conversion.
📅 Supported Date Formats
The package supports 6 common date formats for both Input and Output. By default, the package assumes and returns the YYYY-MM-DD format.
Y-m-d➔ YYYY-MM-DD (Default)Y/m/d➔ YYYY/MM/DDd/m/Y➔ DD/MM/YYYYd-m-Y➔ DD-MM-YYYYm/d/Y➔ MM/DD/YYYYm-d-Y➔ MM-DD-YYYY
📦 Installation
You can install the package via composer into any PHP framework or project:
composer require ashbink/nepali-date
🛠️ Usage
This package is designed for maximum Developer Experience (DX).
You can use it in two ways:
- 1: Global Helper Functions — Best for Blade & Quick Logic
- 2: NepDate Class — Best for Controllers & Services
BS to AD (Nepali to English)
$englishDate = NepDate::toEng('2083-04-25'); /*or*/ $englishDate = nep_to_eng_date('2083-04-25');
Output:
2026-08-10
AD to BS (English to Nepali)
$nepaliDate = NepDate::toNep('2026-08-10'); /*or*/ $nepaliDate = eng_to_nep_date('2026-08-10');
Output:
2083-04-25
BS to AD (Custom Input Format)
// Input is DD/MM/YYYY, output will be default (YYYY-MM-DD) $englishDate = NepDate::toEng('25/04/2083', 'Y-m-d', 'd/m/Y'); /*or*/ $englishDate = nep_to_eng_date('25/04/2083', 'Y-m-d', 'd/m/Y');
Output:
2026-08-10
AD to BS (Custom Input & Output Formats)
// Input is DD/MM/YYYY, output will be default (YYYY-MM-DD) $nepaliDate = NepDate::toNep('08/10/2026', 'Y/m/d', 'm/d/Y'); /*or*/ $nepaliDate = eng_to_nep_date('08/10/2026', 'Y/m/d', 'm/d/Y');
Output:
2083/04/25
Textual Date Conversion with Custom Layouts
You can use standard PHP date formats (Y, F, j, d, m) to format textual output.
// Default Text Format (Y F j) $nepaliText = NepDate::toNepText('2026-08-10'); /*or*/ $nepaliText = eng_to_nep_text('2026-08-10')
Output:
2083 साउन 25
// Custom Text Format (j F Y) $nepaliTextCustom = NepDate::toNepText('2026-08-10', 'j F Y'); /*or*/ $nepaliTextCustom = eng_to_nep_text('2026-08-10')
Output:
25 साउन 2083
// English Text Format $englishText = NepDate::toEngText('2083-04-25', 'F j, Y'); /*or*/ $englishText = nep_to_eng_text('2083-04-25')
Output:
August 10, 2026
In the Classes or Services
If you prefer class-based static calls, you can use the NepDate class.
Example
<?php require_once __DIR__ . '/vendor/autoload.php'; //if required use Ashbink\NepaliDate\NepDate; class EventManager { public function store(string $submittedNepaliDate) { $englishDate = NepDate::toEng($submittedNepaliDate); $todayEnglishDate = date('Y-m-d'); $nepaliDate = NepDate::toNep($todayEnglishDate); header('Content-Type: application/json'); echo json_encode([ 'ad_date' => $englishDate, 'bs_date' => $nepaliDate, ]); exit; } } $event = new EventManager(); $event->store('2082-04-24');
📄 License
The MIT License (MIT). Please see the License file for more information.