PHP code example of sagartimilsina / nepali-date

1. Go to this page and download the library: Download sagartimilsina/nepali-date library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sagartimilsina / nepali-date example snippets


use Sagartimilsina\NepaliDate\Facades\NepaliDate;

$result = NepaliDate::adToBs('2026-07-08');

$result->year;          // 2083
$result->month;         // 3
$result->day;            // 24
$result->monthNameEn;    // "Ashadh"
$result->monthNameNp;    // "असार"
$result->weekdayEn;      // "Wednesday"
$result->weekdayNp;      // "बुधबार"
$result->formattedEn;    // "24 Ashadh 2083"
$result->formattedNp;    // "२४ असार २०८३"

$carbon = NepaliDate::bsToAd('2083-03-24');

$carbon->format('Y-m-d');   // "2026-07-08"



use Sagartimilsina\NepaliDate\NepaliDate;

$date = new NepaliDate();

$result = $date->adToBs('2026-07-08');
echo $result->formattedEn;   // "24 Ashadh 2083"

$carbon = $date->bsToAd('2083-03-24');
echo $carbon->format('Y-m-d');   // "2026-07-08"

try {
    NepaliDate::bsToAd('not-a-date');
} catch (\InvalidArgumentException $e) {
    // "Unable to parse BS date: not-a-date"
}
bash
php artisan vendor:publish --tag=nepali-date-config