PHP code example of dipesh / nepali-date

1. Go to this page and download the library: Download dipesh/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/ */

    

dipesh / nepali-date example snippets


$date = new NepaliDate('1994/01/21');

//or
$date = new NepaliDate();


$date->toNepali(); // output 2050/10/8
//or
$date->toNepali('1994/01/21');

$date->toEnglish(); // 1994/01/21
//or
$date->toEnglish('2050/10/8');

$date->toNepali()->addDays(10);

$date->toNepali()->subDays(10);

$date->toNepali()->addMonths(1);

$date->toNepali()->subMonths(2);

$date->toNepali()->subYears(2);

$date->toNepali()->diff($date2); // returns days

$date->toNepali()->weekDay();

$date->toNepali()->day();

$date->toNepali()->month();

$date->toNepali()->year();

// Suported format Y, m, M, F, d, w, D, l, g

$date->toNepali()->format('Y-m-d'); // 2050-10-8

$date->toNepali()->format('Y F d g l'); // 2050 Magh 8 Gate Sukrabar

$date->isEqual('2048/10/5'); // return true or false

$date->isGreaterThan('2048/10/5');

$date->isGreaterThanOrEqual('2048/10/5');

$date->isLessThan('2048/10/5');

$date->isLessThanOrEqual('2048/10/5');


$date->toNepali()->lang('np')->format('Y-m-d'); // २०५०-१०-८

$date->toNepali()->lang('np')->format('Y F d g l'); // २०५० माघ ८ गते शुक्रबार

//You can also add your own language
$date->toNepali()->lang(function($lang) {
  return $lang; // Provide your own language array
})->format('Y F d g l');

$newDateInstance = (new NepaliDate())->pushLookUpTable(['2091' => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]]);