Nepali DateNepali DateBikram Sambat Date Engine
Class

Packagistnew NepaliDate()

Constructor overloads and initialization options for creating NepaliDate instances in PHP.

The NepaliDate constructor creates instances representing specific points in time mapped to the Bikram Sambat calendar system. You can construct an instance representing the current moment, provide separate year, month, and day integers, supply a standard date string, or pass a native PHP DateTimeInterface object. Bikram Sambat months are indexed starting from 0 for Baisakh through 11 for Chaitra.


Import

use NepaliDateLibrary\NepaliDate;

Signatures

// 1. Current Date and Time
new NepaliDate(): NepaliDate;

// 2. From PHP DateTimeInterface object
new NepaliDate(DateTimeInterface $date): NepaliDate;

// 3. From another NepaliDate instance (copy constructor)
new NepaliDate(NepaliDate $date): NepaliDate;

// 4. From Bikram Sambat date string
new NepaliDate(string $dateString): NepaliDate;

// 5. From separate Year, Month, Day integers
new NepaliDate(int $year, int $month, int $day): NepaliDate;

// 6. From Unix millisecond timestamp
new NepaliDate(int $timestampMs): NepaliDate;

Parameters

ParameterTypeRequiredDescription
$yearOrDateint, string, DateTimeInterface, NepaliDate, nullNoYear integer, ISO date string, DateTimeInterface, or another NepaliDate instance.
$monthint, nullNoZero based month index from 0 for Baisakh to 11 for Chaitra when specifying integers.
$dayint, nullNoDay of the month from 1 to 32 depending on the year and month.

Return Value

  • Type: NepaliDate
  • Description: A newly instantiated NepaliDate instance representing the specified point in time.

Examples

Current Date and Time

use NepaliDateLibrary\NepaliDate;

$now = new NepaliDate();
echo $now->format('YYYY-MM-DD');

From Numeric Coordinates

// Month 0 is Baisakh, Day 1
$newYear = new NepaliDate(2081, 0, 1);
echo $newYear->format('YYYY-MM-DD'); // "2081-01-01"

From Date String

// Delimiters can be hyphens, slashes, or dots
$date1 = new NepaliDate('2081-07-15');
$date2 = new NepaliDate('2081/07/15');
$date3 = new NepaliDate('2081.07.15');

From PHP DateTimeImmutable

use DateTimeImmutable;
use DateTimeZone;
use NepaliDateLibrary\NepaliDate;

$adDate = DateTimeImmutable::createFromFormat('!Y-m-d', '2024-10-31', new DateTimeZone('UTC'));
$nd = new NepaliDate($adDate);
echo $nd->format('YYYY-MM-DD'); // "2081-07-15"

Advertisement

On this page