PHP code example of sarojsardar / laravel-nepali-date
1. Go to this page and download the library: Download sarojsardar/laravel-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/ */
sarojsardar / laravel-nepali-date example snippets
// Convert today's date to Nepali
echo toNepaliDate(now()->format('Y-m-d'));
// Output: २०८१-०८-१५
// Convert specific date
echo toNepaliDate('2024-12-01');
// Output: २०८१-०८-१५
// Basic conversion
echo toNepaliDate('2024-01-15');
// Output: २०८०-१०-०१
// Custom format with month name
echo toNepaliDate('2024-01-15', 'Y F d');
// Output: २०८० पुष ०१
// With day name
echo toNepaliDate('2024-01-15', 'Y F d, l');
// Output: २०८० पुष ०१, सोमवार
// English numerals
echo toNepaliDate('2024-01-15', 'Y-m-d', false);
// Output: 2080-10-01
echo nepaliToday();
// Output: २०८१-०८-१५
echo nepaliToday('Y F d, l');
// Output: २०८१ कार्तिक १५, आइतवार
use SarojSardar\LaravelNepaliDate\NepaliDate;
// Convert date
$nepaliDate = NepaliDate::convertToNepali('2024-01-15');
// Format date
echo NepaliDate::format('2024-01-15', 'Y F d l');
// Output: २०८० पुष ०१ सोमवार
// Today's date
echo NepaliDate::today('Y-m-d');
// Output: २०८१-०८-१५
// Check if year is supported
if (NepaliDate::isValidNepaliYear(2080)) {
echo "Year 2080 is supported";
}
// Get supported year range
$range = NepaliDate::getSupportedYearRange();
// Output: ['min' => 2000, 'max' => 2100]
use SarojSardar\LaravelNepaliDate\Facades\NepaliDate;
// All class methods available through facade
echo NepaliDate::format('2024-01-15', 'Y F d');
echo NepaliDate::today();
$range = NepaliDate::getSupportedYearRange();
$date = '2024-01-15';
echo toNepaliDate($date, 'Y-m-d'); // २०८०-१०-०१
echo toNepaliDate($date, 'Y F d'); // २०८० पुष ०१
echo toNepaliDate($date, 'Y M d'); // २०८० Poush ०१
echo toNepaliDate($date, 'd F Y'); // ०१ पुष २०८०
echo toNepaliDate($date, 'l, d F Y'); // सोमवार, ०१ पुष २०८०
echo toNepaliDate($date, 'Y/m/d'); // २०८०/१०/०१
try {
echo toNepaliDate('invalid-date');
} catch (InvalidArgumentException $e) {
echo "Error: " . $e->getMessage();
}
// Common error scenarios:
// - Invalid date format: "Invalid date format: invalid-date"
// - Date out of range: "Date out of supported range"
// In your AppServiceProvider
public function boot()
{
// Custom logic here
}
// Test basic conversion
$result = toNepaliDate('2024-01-15');
assert($result === '२०८०-१०-०१');
// Test format options
$result = toNepaliDate('2024-01-15', 'Y F d');
assert($result === '२०८० पुष ०१');
// Test English numerals
$result = toNepaliDate('2024-01-15', 'Y-m-d', false);
assert($result === '2080-10-01');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.