This package will extend the carbon to support for nepali date
akashpoudelnp/nepali-date-carbon is a Laravel package for this package will extend the carbon to support for nepali date.
It currently has 1 GitHub stars and 31 downloads on Packagist (latest version v0.2.0).
Install it with composer require akashpoudelnp/nepali-date-carbon.
Discover more Laravel packages by akashpoudelnp
or browse all Laravel packages to compare alternatives.
Last updated
This is a powerful package that extends Laravel's Carbon to support Nepali (Bikram Sambat) dates. It provides an elegant way to convert between Gregorian (AD) and Nepali (BS) calendar systems, format dates in Nepali, and display dates in Nepali language.
Install the package via Composer:
composer require akashpoudelnp/nepali-date-carbon
You can convert any Carbon instance to a Nepali Date:
use Carbon\Carbon;
// Convert current date to BS
$nepaliDate = now()->convertToBS();
echo $nepaliDate->format('Y-m-d'); // "2080-12-15"
// Convert a specific date to BS
$date = Carbon::parse('2023-05-15');
$nepaliDate = $date->convertToBS();
echo $nepaliDate->format('Y F d'); // "2080 Jestha 01"
You can also convert a Nepali Date back to a Gregorian Date:
use Carbon\Carbon;
// Convert current BS date to AD
$gregorianDate = now()->createFromBS($year, $month, $day);
echo $gregorianDate->format('Y-m-d'); // "2023-05-15"
You can format Nepali dates using the format method:
$nepaliDate = now()->convertToBS();
echo $nepaliDate->format('Y F d'); // "2080 Jestha 01"
echo $nepaliDate->format('l, F j, Y'); // "Saturday, Jestha 01, 2080"
The format method supports standard Carbon date formatting options, but with Nepali date formats. Here are some common format characters you can use:
Y: Year (4 digits)F: Full month named: Day of the month (2 digits)l: Full name of the day of the weekj: Day of the month without leading zerosD: Short day namem: Month number (2 digits)n: Month number without leading zerosg: Hour in 12-hour format without leading zerosG: Hour in 24-hour format without leading zerosh: Hour in 12-hour format with leading zerosH: Hour in 24-hour format with leading zerosi: Minutes with leading zeross: Seconds with leading zerosThe package supports Nepali language localization. You can pass the $isNepali parameter to the format method or
convertToBS
to get the date in Nepali language:
$nepaliDate = now()->convertToBS(
format: 'Y-m-d',
inNepali: true // Or use can use app()->isLocale('ne') to check if the app locale is Nepali
);
echo $nepaliDate; // "२०८०-१२-१५"
To run the tests, use the following command:
composer test
We welcome contributions to this package! Please read our contributing guidelines for details on how to get started.
This package is open-sourced software licensed under the MIT license.