ashbin/nepali-date

There is no license information available for the latest version (v1.0.0) of this package.

A lightweight Laravel package for converting BS to AD and vice versa.

Maintainers

Package info

github.com/ashbink/nepali-date

pkg:composer/ashbin/nepali-date

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-10 12:44 UTC

This package is auto-updated.

Last update: 2026-08-11 05:06:08 UTC


README

A lightweight, blazing-fast, and optimized Laravel package to convert Nepali Date (Bikram Sambat - BS) to English Date (Anno Domini - AD) and vice versa.

Instead of relying on complex and often inaccurate mathematical formulas, this package uses a highly accurate database-driven lookup approach based on the official Nepali calendar.

🚀 Features

  • 100% Accurate BS to AD conversion.
  • 100% Accurate AD to BS conversion.
  • Easy-to-use Global Helper Functions (Great for Blade).
  • Clean Facade support (Great for Controllers).
  • Database-driven for lightning-fast micro-second queries.
  • Zero configuration required.

📦 Installation

You can install the package via Composer into any Laravel project:

composer require ashbin/nepali-date

⚙️ Setup Instructions

After installing the package, you need to set up the database table and populate it with the official calendar data.

Run this commands in your terminal:

php artisan migrate

This will create a lightweight nepali_calendars table in your database and populates the accurate BS to AD mapped data.

🛠️ Usage

This package is designed for maximum Developer Experience (DX).

You can use it in two ways:

  • Method 1: Global Helper Functions — Best for Blade & Quick Logic
  • Method 2: NepDate Facade — Best for Controllers & Services

1️⃣ Method 1: Using Global Helper Functions

You can use these helper functions anywhere in your Laravel app without importing any classes.

BS to AD (Nepali to English)

$englishDate = nep_to_eng_date('2083-04-25');

Output:

2026-08-10

AD to BS (English to Nepali)

$nepaliDate = eng_to_nep_date('2026-08-10');

Output:

2083-04-25

Example in Blade Templates

<div>
    <p>
        Joined Date (BS):
        {{ eng_to_nep_date($user->created_at->format('Y-m-d')) }}
    </p>

    <p>
        Event Date (AD):
        {{ nep_to_eng_date($event->bs_date) }}
    </p>
</div>

2️⃣ Method 2: Using the Facade

If you prefer class-based static calls, you can use the NepDate facade.

The facade is auto-discovered, so you don't need to register it manually.

Example

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use NepDate;

class EventController extends Controller
{
    public function store(Request $request)
    {
        // Convert BS input to AD for database storage
        $englishDate = NepDate::toEng(
            $request->input('nepali_date')
        );

        // Convert AD from database back to BS for API response
        $nepaliDate = NepDate::toNep(
            now()->format('Y-m-d')
        );

        return response()->json([
            'ad_date' => $englishDate,
            'bs_date' => $nepaliDate,
        ]);
    }
}

BS to AD using Facade

$englishDate = NepDate::toEng('2083-04-25');

Output:

2026-08-10

AD to BS using Facade

$nepaliDate = NepDate::toNep('2026-08-10');

Output:

2083-04-25

📅 Supported Date Format

The package uses the following date format:

YYYY-MM-DD

BS Date

2083-04-25

AD Date

2026-08-10

🔄 Conversion Examples

BS Date AD Date
2083-04-25 2026-08-10

BS → AD

nep_to_eng_date('2083-04-25');

Output:

2026-08-10

AD → BS

eng_to_nep_date('2026-08-10');

Output:

2083-04-25

📄 License

The MIT License (MIT). Please see the License file for more information.