PHPackages                             penobit/persiandate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. penobit/persiandate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

penobit/persiandate
===================

Persian datetime package to use and manipulate Persian (jalali) datetime.

v1.2.5(2y ago)1433MITPHPPHP ^7.0 | ^7.1 | ^7.2 | ^8.0 | ^8.1 | ^8.2

Since Jan 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/penobit/persiandate)[ Packagist](https://packagist.org/packages/penobit/persiandate)[ RSS](/packages/penobit-persiandate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (15)Used By (0)

PersianDate
===========

[](#persiandate)

- PersianDate calendar is a solar calendar that was used in Persia, variants of which today are still in use in Iran as well as Afghanistan.

Requirements
------------

[](#requirements)

- `php >= 7.0`

Run the Composer update command

```
composer require penobit/persiandate

```

### PersianDate Class and helpers

[](#persiandate-class-and-helpers)

#### `now([$timestamp = null])`

[](#nowtimestamp--null)

```
// the default timestamp is Now
$date = \Penobit\PersianDate\PersianDate::now()
// OR
$date = persianDate();

// pass timestamps
$date = PersianDate::forge(1333857600);
// OR
$date = persianDate(1333857600);

// pass human readable strings to make timestamps
$date = PersianDate::forge('last sunday');

// get the timestamp
$date = PersianDate::forge('last sunday')->getTimestamp(); // 1333857600

// format the timestamp
$date = PersianDate::forge('last sunday')->format('%B %d، %Y'); // دی 02، 1391
$date = PersianDate::forge('today')->format('%A, %d %B %y'); // جمعه، 23 اسفند 97

// get a predefined format
$date = PersianDate::forge('last sunday')->format('datetime'); // 1391-10-02 00:00:00
$date = PersianDate::forge('last sunday')->format('date'); // 1391-10-02
$date = PersianDate::forge('last sunday')->format('time'); // 00:00:00

// get relative 'ago' format
$date = PersianDate::forge('now - 10 minutes')->ago() // 10 دقیقه پیش
// OR
$date = PersianDate::forge('now - 10 minutes')->ago() // 10 دقیقه پیش
```

#### Methods api

[](#methods-api)

---

```
public static function now(\DateTimeZone $timeZone = null): PersianDate

$persianDate = PersianDate::now();
```

---

```
public static function fromCarbon(Carbon $carbon): PersianDate

$persianDate = PersianDate::fromCarbon(Carbon::now());
```

---

```
public static function fromFormat(string $format, string $timestamp, \DateTimeZone$timeZone = null): PersianDate

$persianDate = PersianDate::fromFormat('Y-m-d H:i:s', '1397-01-18 12:00:40');
```

---

```
public static function forge($timestamp, \DateTimeZone $timeZone = null): PersianDate

// Alias fo fromDatetime
```

---

```
public static function fromDateTime($dateTime, \DateTimeZone $timeZone = null): PersianDate

$persianDate = PersianDate::fromDateTime(Carbon::now())
// OR
$persianDate = PersianDate::fromDateTime(new \DateTime());
// OR
$persianDate = PersianDate::fromDateTime('yesterday');
```

---

```
public function getMonthDays(): int

$date = (new PersianDate(1397, 1, 18))->getMonthDays()
// output: 31
```

---

```
public function getMonth(): int

$date = (new PersianDate(1397, 1, 18))->getMonth()
// output: 1
```

---

```
public function isLeapYear(): bool

$date = (new PersianDate(1397, 1, 18))->isLeapYear()
// output: false
```

---

```
public function getYear(): int

$date = (new PersianDate(1397, 1, 18))->getYear()
// output: 1397
```

---

```
public function subMonths(int $months = 1): PersianDate

$date = (new PersianDate(1397, 1, 18))->subMonths(1)->toString()
// output: 1396-12-18 00:00:00
```

---

```
public function subYears(int $years = 1): PersianDate

$date = (new PersianDate(1397, 1, 18))->subYears(1)->toString()
// output: 1396-01-18 00:00:00
```

---

```
public function getDay(): int

$date = (new PersianDate(1397, 1, 18))->getDay()
// output: 18
```

---

```
public function getHour(): int

$date = (new PersianDate(1397, 1, 18, 12, 0, 0))->getHour()
// output: 12
```

---

```
public function getMinute(): int

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->getMinute()
// output: 10
```

---

```
public function getSecond(): int

$date = (new PersianDate(1397, 1, 18, 12, 10, 45))->getSecond()
// output: 45
```

---

```
public function getTimezone(): \DateTimeZone

// Get current timezone
```

---

```
public function addMonths(int $months = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->addMonths(1)->format('m')
// output: 02
```

---

```
public function addYears(int $years = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->addYears(1)->format('Y')
// output: 1398
```

---

```
public function getDaysOf(int $monthNumber = 1): int

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->getDaysOf(1)
// output: 31
```

---

```
public function addDays(int $days = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->addDays(1)->format('d')
// output: 18
```

---

```
public function toCarbon(): Carbon

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->toCarbon()->toDateTimeString()
// output: 2018-04-07 12:10:00
```

---

```
public function subDays(int $days = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->subDays(10)->format('d')
// output: 08
```

---

```
public function addHours(int $hours = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->addHours(1)->format('H')
// output: 13
```

---

```
public function subHours(int $hours = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->subHours(1)->format('H')
// output: 11
```

---

```
public function addMinutes(int $minutes = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->addMinutes(10)->format('i')
// output: 22
```

---

```
public function subMinutes(int $minutes = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->subMinutes(10)->format('i')
// output: 02
```

---

```
public function addSeconds(int $secs = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->addSeconds(10)->format('s')
// output: 10
```

---

```
public function subSeconds(int $secs = 1): PersianDate

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->subSeconds(10)->format('i:s')
// output: 11:40
```

---

```
public function equalsTo(PersianDate $other): bool

$date = (new PersianDate(1397, 1, 18, 12, 10, 0))->equalsTo(PersianDate::now())
// output: false

$date = PersianDate::now()->equalsTo(PersianDate::now())
// output: true
```

---

```
public function equalsToCarbon(Carbon $carbon): bool

$date = PersianDate::now()->equalsToCarbon(Carbon::now())
// output: true
```

---

```
public function greaterThan(PersianDate $other): bool

$date = PersianDate::now()->greaterThan(PersianDate::now()->subDays(1)))
// output: true
```

---

```
public function greaterThanCarbon(Carbon $carbon): bool

$date = PersianDate::now()->greaterThanCarbon(Carbon::now()->subDays(1)))
// output: true
```

---

```
public function lessThan(PersianDate $other): bool

$date = PersianDate::now()->lessThan(PersianDate::now()->addDays(1)))
// output: true
```

---

```
public function lessThanCarbon(Carbon $carbon): bool

$date = PersianDate::now()->lessThanCarbon(Carbon::now()->addDays(1)))
// output: true
```

---

```
public function greaterThanOrEqualsTo(PersianDate $other): bool

$date = PersianDate::now()->greaterThan(PersianDate::now()->subDays(1)))
// output: true
```

---

```
public function greaterThanOrEqualsToCarbon(Carbon $carbon): bool

$date = PersianDate::now()->greaterThanOrEqualsToCarbon(Carbon::now()))
// output: true
```

---

```
public function lessThanOrEqualsTo(PersianDate $other): bool

$date = PersianDate::now()->lessThanOrEqualsTo(PersianDate::now()))
// output: true
```

---

```
public function lessThanOrEqualsToCarbon(Carbon $carbon): bool

$date = PersianDate::now()->lessThanOrEqualsToCarbon(Carbon::now()))
// output: true
```

---

```
public function isStartOfWeek(): bool

$date = (new PersianDate(1397, 6, 24))->isStartOfWeek()
// output: true
```

---

```
public function isSaturday(): bool

$date = (new PersianDate(1397, 6, 24))->isSaturday()
// output: true
```

---

```
public function isDayOfWeek(int $day): bool

$date = (new PersianDate(1397, 6, 24))->isDayOfWeek(0)
// output: true
```

---

```
public function isEndOfWeek(): bool

$date = (new PersianDate(1397, 6, 24))->isEndOfWeek()
// output: false
```

---

```
public function isFriday(): bool

$date = (new PersianDate(1397, 6, 24))->isFriday()
// output: false
```

---

```
public function isToday(): bool

$date = (new PersianDate(1397, 6, 24))->isToday()
// output: (!maybe) true
```

---

```
public function isTomorrow(): bool

$date = (new PersianDate(1397, 6, 25))->isTomorrow()
// output: true
```

---

```
public function isYesterday(): bool

$date = (new PersianDate(1397, 6, 23))->isYesterday()
// output: true
```

---

```
public function isFuture(): bool

$date = (new PersianDate(1397, 6, 26))->isFuture()
// output: true
```

---

```
public function isPast(): bool

$date = (new PersianDate(1397, 5, 24))->isPast()
// output: true
```

---

```
public function toArray(): array
$date = (new PersianDate(1397, 6, 24))->toArray()
// output: (
//     [year] => 1397
//     [month] => 6
//     [day] => 24
//     [dayOfWeek] => 0
//     [dayOfYear] => 179
//     [hour] => 0
//     [minute] => 0
//     [second] => 0
//     [micro] => 0
//     [timestamp] => 1536969600
//     [formatted] => 1397-06-24 00:00:00
//     [timezone] =>
// )
```

---

```
public function getDayOfWeek(): int

$date = (new PersianDate(1397, 5, 24))->getDayOfWeek()
// output: 0
```

---

```
public function isSunday(): bool

$date = (new PersianDate(1397, 6, 24))->isSunday()
// output: false
```

---

```
public function isMonday(): bool

$date = (new PersianDate(1397, 6, 26))->isMonday()
// output: true
```

---

```
public function isTuesday(): bool

$date = (new PersianDate(1397, 6, 24))->isTuesday()
// output: false
```

---

```
public function isWednesday(): bool

$date = (new PersianDate(1397, 6, 24))->isWednesday()
// output: false
```

---

```
public function isThursday(): bool

$date = (new PersianDate(1397, 6, 22))->isThursday()
// output: true
```

---

```
public function getDayOfYear(): int

$date = (new PersianDate(1397, 5, 24))->getDayOfYear()
// output: 179
```

---

```
public function toString(): string
$date = (new PersianDate(1397, 5, 24))->isPast()
// output: 1397-05-24 00:00:00
```

---

```
public function format(string $format): string

$date = (new PersianDate(1397, 5, 24))->format('y')
// output: 1397
// see php date formats
```

---

```
public function __toString(): string

// Alias of toString()
```

---

```
public function ago(): string
```

---

```
public function getTimestamp(): int
```

---

```
public function getNextWeek(): PersianDate
```

---

```
public function getNextMonth(): PersianDate
```

---

### CalendarUtils

[](#calendarutils)

---

#### `checkDate($year, $month, $day, [$isPersianDate = true])`

[](#checkdateyear-month-day-ispersiandate--true)

```
// Check persian date
\Penobit\PersianDate\CalendarUtils::checkDate(1391, 2, 30, true); // true

// Check persian date
\Penobit\PersianDate\CalendarUtils::checkDate(2016, 5, 7); // false

// Check gregorian date
\Penobit\PersianDate\CalendarUtils::checkDate(2016, 5, 7, false); // true
```

---

#### `toPersianDate($gYear, $gMonth, $gDay)`

[](#topersiandategyear-gmonth-gday)

```
\Penobit\PersianDate\CalendarUtils::toPersianDate(2016, 5, 7); // [1395, 2, 18]
```

---

#### `toGregorian($jYear, $jMonth, $jDay)`

[](#togregorianjyear-jmonth-jday)

```
\Penobit\PersianDate\CalendarUtils::toGregorian(1395, 2, 18); // [2016, 5, 7]
```

---

#### `strftime($format, [$timestamp = false, $timezone = null])`

[](#strftimeformat-timestamp--false-timezone--null)

```
CalendarUtils::strftime('Y-m-d', strtotime('2016-05-8')); // 1395-02-19
```

---

#### `createDateTimeFromFormat($format, $jalaiTimeString)`

[](#createdatetimefromformatformat-jalaitimestring)

```
$PersianDate = '1394/11/25 15:00:00';

// get instance of \DateTime
$dateTime = \Penobit\PersianDate\CalendarUtils::createDatetimeFromFormat('Y/m/d H:i:s', $PersianDate);
```

---

#### `createCarbonFromFormat($format, $jalaiTimeString)`

[](#createcarbonfromformatformat-jalaitimestring)

```
$PersianDate = '1394/11/25 15:00:00';

// get instance of \Carbon\Carbon
$carbon = \Penobit\PersianDate\CalendarUtils::createCarbonFromFormat('Y/m/d H:i:s', $PersianDate);
```

---

#### `convertNumbers($string)`

[](#convertnumbersstring)

```
// convert latin to persian
$date = \Penobit\PersianDate\CalendarUtils::strftime('Y-m-d', strtotime('2016-05-8'); // 1395-02-19
\Penobit\PersianDate\CalendarUtils::convertNumbers($date); // ۱۳۹۵-۰۲-۱۹

// convert persian to latin
$dateString = \Penobit\PersianDate\CalendarUtils::convertNumbers('۱۳۹۵-۰۲-۱۹', true); // 1395-02-19
\Penobit\PersianDate\CalendarUtils::createCarbonFromFormat('Y-m-d', $dateString)->format('Y-m-d'); //2016-05-8
```

#### `startOfYear()`

[](#startofyear)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->startOfYear(); // 1400-01-01 00:00:00
```

#### `endOfYear()`

[](#endofyear)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->endOfYear(); // 1400-12-59 23:59:59
```

#### `startOfWeek()`

[](#startofweek)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->startOfWeek(); // 1400-11-30 00:00:00
```

#### `endOfWeek()`

[](#endofweek)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->endOfWeek(); // 1400-12-06 23:59:59
```

#### `startOfMonth()`

[](#startofmonth)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->startOfMonth(); // 1400-12-01 00:00:00
```

#### `endOfMonth()`

[](#endofmonth)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->endOfMonth(); // 1400-12-29 23:59:59
```

#### `startOfYear()`

[](#startofyear-1)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->startOfYear(); // 1400-01-01 00:00:00
```

#### `endOfYear()`

[](#endofyear-1)

```
$date = new \Penobit\PersianDate\PersianDate(); // 1400-12-02 17:50
$date->endOfYear(); // 1400-12-29 23:59:59
```

---

#### `Carbon api-difference`

[](#carbon-api-difference)

You can convert date/time to [briannesbitt/carbon](https://github.com/briannesbitt/carbon), thus being able to use it's [API](https://carbon.nesbot.com/docs/) to work with PHP DateTime class.

##### [Difference](https://carbon.nesbot.com/docs/#api-difference) in months

[](#difference-in-months)

```
// convert persian to Carbon
$date = \Penobit\PersianDate\PersianDate::fromFormat('Y-m-d', "1395-02-19")->toCarbon();
// ->toString() => Sun May 08 2016 00:00:00 GMT+0000

// Add 4 months to Carbon
$dateAdd4Months = $date->addMonths(4);

// Difference in months
$dateAdd4Months->DiffInMonths($date); //4
$dateAdd4Months->floatDiffInMonths($date); //4.0
```

---

Formatting
----------

[](#formatting)

For help in building your formats, checkout the [PHP strftime() docs](http://php.net/manual/en/function.strftime.php).

Notes
-----

[](#notes)

The class relies on `strtotime()` to make sense of your strings, and `strftime()` to handle the formatting. Always check the `time()` output to see if you get false timestamps, it which case, means the class couldn't understand what you were asking it to do.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~71 days

Total

14

Last Release

853d ago

PHP version history (2 changes)v1.0.1PHP ^7.0 | ^7.1 | ^7.2 | ^8.0 | ^8.1

v1.1.3PHP ^7.0 | ^7.1 | ^7.2 | ^8.0 | ^8.1 | ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cbcaf2d9ebcdc5282f9dde8aeb9e6cff2d8bd8735b21669fb242e3a47dd7642?d=identicon)[penobit](/maintainers/penobit)

---

Top Contributors

[![penobit](https://avatars.githubusercontent.com/u/60283818?v=4)](https://github.com/penobit "penobit (29 commits)")

---

Tags

laraveldatetimedatejDatejalali\_datepersian datetimepenobitPersianDate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/penobit-persiandate/health.svg)

```
[![Health](https://phpackages.com/badges/penobit-persiandate/health.svg)](https://phpackages.com/packages/penobit-persiandate)
```

###  Alternatives

[morilog/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.

9201.2M45](/packages/morilog-jalali)[hekmatinasser/verta

This Package helps developers to work with Jalali Datetime class for Laravel Framework PHP

657530.5k27](/packages/hekmatinasser-verta)[aloko/nova-persian-datepicker

Persian Datepicker for Laravel Nova.

203.5k](/packages/aloko-nova-persian-datepicker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
