Download the PHP package rohanadhikari/nepali-date without Composer

On this page you can find all versions of the php package rohanadhikari/nepali-date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package nepali-date

NepaliDate

Latest Version on Packagist Total Downloads

A PHP package for handling Nepali Date and Time (Bikram Sambat - BS) with full support for localization, date manipulation, and formatting. All calculations are based on the Nepali calendar, making it perfect for applications targeting Nepali users or systems that operate primarily in BS.


[!NOTE]
v1-beta is optimized for fast date conversions by minimizing computational overhead. Additional optimization steps are planned. You can try v1-beta and share your feedback to help improve it.


🚀 Features


📦 Installation

Install via Composer:


Usage

[!NOTE]
You can see the available constants here

Using in native PHP (no framework)

If you're not using a framework, you can still use this package in plain PHP. The easiest way is to install via Composer and include the generated autoloader.

Notes:


⚙️ Initialize

Create a new NepaliDate instance in different ways depending on your use case.


Now

Returns a NepaliDate instance initialized with the current Nepali date and time.

Parameters:

Example:


Using PHP Native DateTime

Create a NepaliDate instance directly from a PHP native DateTime (AD).
This automatically converts the Gregorian (AD) date into the Nepali (BS) calendar.


Using DateTime Notation

Create a NepaliDate instance using a natural language date string (like 'now', 'yesterday', 'tomorrow').
This internally parses the notation using Native DateTime and converts it into a corresponding Nepali (BS) date.

Example


Using Unix Timestamp

Create a NepaliDate instance from a Unix timestamp.
This method first converts the timestamp into a PHP DateTime object and then translates it into the equivalent Nepali (BS) date and time.

Parameters


Direct

Manually create a new NepaliDate instance by providing all date components.

Parameters


Format

Formats the NepaliDate instance according to the provided pattern and locale-specific rules, and returns a string of the formatted date. You can also use predefined fromat pattern from Constants.

List of Available Formats Tokens

Format Output Example Meaning
Y 2082 Year
y 82 Two-digit year
m 2 Month (1–12)
n 02 Month, two digits
M Bai Short month name
F Baisakh Full month name
d 09 Two-digit day
j 9 Day
D Sun Short weekday name
l Sunday Full weekday name
w 1 Weekday number (Sunday=1, Monday=2…)
G 7 Hour, 24-hour clock
H 07 Hour, 24-hour clock, 2-digits
h 23 Hour, 12-hour clock
g 12 Hour, 12-hour clock, 2-digits
a am / pm Meridiem (lowercase)
A AM / PM Meridiem (uppercase)
i 59 Minute, 2-digits
s 59 Second, 2-digits
e Asia/Kathmandu Timezone name
O +0530 Timezone offset
P +05:45 Timezone offset with colon
Z 20700 Timezone offset in seconds
c 2082-02-01T14:30:00+05:45 ISO 8601 datetime
r Sun, 01 Bai 2082 14:30:00 +0530 RFC 2822 datetime
U 1675289400 Unix timestamp (Using Ad Date and Time)

Example:


🌐 Locale

Available locales: en and np.

Example:

[!Note] You can also set the global default locale as:-

Any new instance of NepaliDate will now use this locale by default.


Parse

The NepaliDate class provides the parse() method, which allows you to create a NepaliDate instance from a string. It supports multiple default format patterns, and you can also add custom parse patterns to handle other string formats or use createFromFormat.

Default format patterns supported for parsing:

Format Pattern
Y-m-d
Y-n-d
Y-m-d H:i:s
Y-m-d h:i:s A
h:i A
h:i:s A
H:i
H:i:s
U
c
r
D, d M Y H:i:s
l, F j, Y g:i A

Example:


CreateFromFormat

The NepaliDate class provides the createFromFormat() method, which allows you to create a NepaliDate instance from a string using a specific format.

Example:


➕ Unit Operations (Add/Subtract)

Available Methods

Unit Add Method Subtract Method
Year addYear() subYear()
Year addYears($n) subYears($n)
Month addMonth() subMonth()
Month addMonths($n) subMonths($n)
Day addDay() subDay()
Day addDays($n) subDays($n)
Hour addHour() subHour()
Hour addHours($n) subHours($n)
Minute addMinute() subMinute()
Minute addMinutes($n) subMinutes($n)
Second addSecond() subSecond()
Second addSeconds($n) subSeconds($n)

Example:


Dates Difference

Currently this difference feature is avialable for english only as it just convert date into AdDate and return builtin DateInterval instance. But feature for nepali locale will be avialble in future version. Example:


🔍 Getters

🕰️ Year / Era

Method Description Example
getMillennium() Returns millennium number . 3 → for 2082
getCentury() Returns century number . 21
getDecade() Returns decade number . 209
getYear() Returns full year. 2082
getShortYear() Returns last two digits of the year. "82"

⏰ Time (24-hour)

Method Description Example
getHour() Hour in 24-hour format (0–23). 14
getTwoDigitHour() Two-digit 24-hour format. "14"
getMinute() Minute (0–59). 45
getTwoDigitMinute() Two-digit minute string. "45"
getSecond() Second (0–59). 9
getTwoDigitSecond() Two-digit second string. "09"

📆 Day

Method Description Example
getDay() Day of the month. 12
getTwoDigitDay() Two-digit day string. "12"
getWeekDay() Day of week (1 = Sunday → 7 = Saturday). 1

📅 Month

Method Description Example
getMonth() Month number (1–12). 5
getTwoDigitMonth() Two-digit month. "05"
getQuarter() Returns quarter number (1–4). 2
getDaysInMonth() Total days in the given BS month. 32

🕛 Time (12-hour)

Method Description Example
getShortHour() Hour in 12-hour format. 2
getTwoDigitShortHour() Two-digit 12-hour format. "02"
getMaridian() Returns "AM" or "PM". "PM"

🌍 Timezone

Method Description Example
getTimezone() Returns timezone object. DateTimeZone('Asia/Kathmandu')
getTimezoneName() Returns timezone name. "Asia/Kathmandu"
getTZName() Alias for getTimezoneName(). "Asia/Kathmandu"

🈯 Locale-Based

Method Description Example Output (Nepali)
getLocale() Current Locale. "np"
getLocaleMillennium() Localized millennium number. "३"
getLocaleCentury() Localized century number. "२१"
getLocaleDecade() Localized decade number. "२०९"
getLocaleYear() Localized year. "२०८२"
getLocaleShortYear() Localized short year. "८२"
getLocaleQuarter() Localized quarter number. "२"
getLocaleMonth() Localized month number. "५"
getLocaleTwoDigitMonth() Localized two-digit month. "०५"
getLocaleMonthName() Localized month name. "बैशाख"
getLocaleShortMonthName() Localized short month name. "बै"
getLocaleWeekDay() Localized weekday number. "१"
getLocaleWeekDayName() Localized weekday name. "आइतबार"
getLocaleShortWeekDayName() Localized short weekday name. "आइत"
getLocaleDay() Localized day. "१२"
getLocaleTwoDigitDay() Localized two-digit day. "१२"
getLocaleHour() Localized 24-hour format. "१४"
getLocaleShortHour() Localized 12-hour format. "२"
getLocaleTwoDigitShortHour() Localized two-digit 12-hour. "०२"
getLocaleTwoDigitHour() Localized two-digit 24-hour. "१४"
getLocaleMinute() Localized minute. "४५"
getLocaleTwoDigitMinute() Localized two-digit minute. "४५"
getLocaleSecond() Localized second. "९"
getLocaleTwoDigitSecond() Localized two-digit second. "०९"
getLocaleMaridian() Localized AM/PM (currently English). "PM"

Shorthand & Property Access

For any getter method, you can:

Example:


⚙️ Setters

🔹 Basic Setters

Method Description
setYear(int $year) Sets the BS year.
setMonth(int $month) Sets the BS month (1–12).
setDay(int $day) Sets the BS day of the month.
setHour(int $hour) Sets the hour (0–23).
setMinute(int $minute) Sets the minute (0–59).
setSecond(int $second) Sets the second (0–59).
setTimeZone(int\|DateTimeZone\|string $value) Sets the time zone (aliases: timeZone, tZone, tZ).

🔹 Unit-Based Setter

Method Description
setUnit(string\|NepaliUnit $unit, $value) Sets a specific unit (year, month, day, hour, minute, second, timezone).

🔹 Combined Setters

Method Description
setDate(int $year, int $month, int $day) Sets year, month, and day together.
setTime(int $hour, int $minute, int $second) Sets hour, minute, and second together.

Shorthand & Property Assignment

You can also use setter variants in two shorter forms, similar to getters:

  1. Without set (camelCase):

  2. As property assignment (Only Support for mutable instance).

Example:


Shifting

The NepaliDate provides methods to shift dates to their corresponding values based on different contexts like timezone or week.

TimeZone


Week


📏 Boundaries Methods

Boundary methods are used to snap a date/time to the start or end of a defined unit. This is extremely useful for:

Available Methods

Method Description
startOfDay() Sets the time to the very beginning of the day (00:00:00).
endOfDay() Sets the time to the very end of the day (23:59:59).
startOfWeek($weekStart) Moves the date to the first day of the week (Sunday by default, customizable).
endOfWeek($weekEnd) Moves the date to the last day of the week (Saturday by default, customizable).
startOfMonth() Moves the date to the first day of the month at 00:00:00.
endOfMonth() Moves the date to the last day of the month at 23:59:59.
startOfQuarter() Moves the date to the first day of the current quarter at 00:00:00.
endOfQuarter() Moves the date to the last day of the current quarter at 23:59:59.
startOfYear() Moves the date to the first day of the year at 00:00:00.
endOfYear() Moves the date to the last day of the year at 23:59:59.
startOfDecade() Moves the date to the first year of the decade at 00:00:00.
endOfDecade() Moves the date to the last year of the decade at 23:59:59.
startOfCentury() Moves the date to the first year of the century at 00:00:00.
endOfCentury() Moves the date to the last year of the century at 23:59:59.
startOfMillennium() Moves the date to the first year of the millennium at 00:00:00.
endOfMillennium() Moves the date to the last year of the millennium at 23:59:59.
startOfHour() Sets minutes and seconds to 00:00 of the current hour.
endOfHour() Sets minutes and seconds to 59:59 of the current hour.
startOfMinute() Sets seconds to 00 of the current minute.
endOfMinute() Sets seconds to 59 of the current minute.
startOf(unit) Generic method to snap the date to the start of a specified unit (day, month, year, etc.).
endOf(unit) Generic method to snap the date to the end of a specified unit (day, month, year, etc.).

Example:


🔎 Comparison

The NepaliDate class provides a comprehensive set of comparison and state-checking methods.
These methods allow you to compare dates, check if a date falls within a range, or determine its temporal state (past, future, today, etc.).
All methods accept either another NepaliDateInterface instance or a date string that can be parsed into a Nepali date.

Method Alias / Shortcut Description
equalTo($date) eq($date) Returns true if the current date is equal to the given date.
notEqualTo($date) ne($date) Returns true if the current date is not equal to the given date.
greaterThan($date) gt($date), isAfter($date) Returns true if the current date is after the given date.
greaterThanOrEqualTo($date) gte($date) Returns true if the current date is after or equal to the given date.
lessThan($date) lt($date), isBefore($date) Returns true if the current date is before the given date.
lessThanOrEqualTo($date) lte($date) Returns true if the current date is before or equal to the given date.
between($date1, $date2, $equal = true) isBetween($date1, $date2, $equal = true) Returns true if the current date is between two dates (inclusive by default).
betweenIncluded($date1, $date2) Returns true if the current date is between two dates, inclusive.
betweenExcluded($date1, $date2) Returns true if the current date is between two dates, exclusive.
isWeekday() Returns true if the current date is a weekday (not Saturday).
isWeekend() Returns true if the current date is a weekend (Saturday).
isYesterday() Returns true if the current date represents yesterday.
isToday() Returns true if the current date represents today.
isTomorrow() Returns true if the current date represents tomorrow.
isFuture() Returns true if the current date is in the future.
isPast() Returns true if the current date is in the past.
isNowOrFuture() Returns true if the current date is now or in the future.
isNowOrPast() Returns true if the current date is now or in the past.

Example:


Additional

Usage in Laravel Example

For detailed instructions on using NepaliDate in a Laravel application, see the Laravel Integration Guide.


🌐 Locale Customization

You can customize locale data for months, weekdays, numbers, and more.
For detailed instructions, see the LocaleCustomize documentation.


⚡ Custom Functions / Macros

You can also add your own functions or macros to extend NepaliDateTime functionality.
For detailed instructions, see the Macro documentation.


NepaliNumbers

You can also use the NepaliNumbers class to work with Nepali numerals. For detailed information, see the NepaliNumbers documentation.



All versions of nepali-date with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rohanadhikari/nepali-date contains the following files

Loading the files please wait ...