PHP Packagev8.6.xMIT License45.2K+ downloads

Hijri: Hijri dates the Carbon way

Turn any Carbon date into "1 Ramadan 1445" with one toHijri() call, and convert it back just as easily.

$composer require pharaonic/php-hijri
Key Features

Everything you need to work with Hijri dates

Register one Carbon mixin and every date in your app speaks Hijri.

Gregorian to Hijri

Call toHijri() on any Carbon date, or Hijri::parse() on any string Carbon understands.

Hijri to Gregorian

Build a Gregorian Carbon date from Hijri parts with Carbon::fromHijri(1445, 9, 1).

Hijri String Parsing

Parse YYYY-MM-DD Hijri strings with an optional time using Carbon::parseHijri().

Arabic and English Months

Month names switch between Arabic and transliterated English based on the Carbon locale.

Day Adjustment

Shift conversions by whole days to match local moon sighting, globally or per call.

Calendar Validation

HijriCalendar checks leap years, month lengths, and whether a Hijri date exists.

A quick look

Convert a Gregorian date to Hijri and back again.

index.php
1use Carbon\Carbon;
2use Pharaonic\Hijri\HijriCarbon;
3 
4Carbon::mixin(HijriCarbon::class);
5 
6Carbon::parse('2024-03-11')->toHijri()->isoFormat('dddd D MMMM YYYY');
7// "Monday 1 Ramadan 1445"
8 
9Carbon::fromHijri(1445, 10, 1)->toDateString();
10// "2024-04-10"
FAQ

Hijri Questions

Quick answers about installing and using Hijri.

What is Hijri?

Hijri (Islamic) date support for PHP built on Carbon. Convert Gregorian dates to Hijri and back, parse Hijri strings, and format month names in Arabic or English. It's a free, open-source PHP package by Pharaonic.

How do I install Hijri?

Run composer require pharaonic/php-hijri in your project's root directory.

What does Hijri require?

The latest release requires PHP 8.6+.

Is Hijri free to use?

Yes. Hijri is open source under the MIT license, so you can use it in personal and commercial projects.

Which Hijri calendar does Hijri use?

It uses the tabular (arithmetic) Islamic calendar, the same 30-year cycle used by most software. Real-world dates can differ by a day or two from local moon sighting, so the package lets you shift results with a day adjustment.

How do I show month names in Arabic?

Set an Arabic locale, either globally with Carbon::setLocale('ar') or per date with ->locale('ar'). Any ar locale uses the Arabic month names; every other locale uses the English transliteration.

Does it need the PHP calendar extension?

No. The Julian Day math is done in plain PHP, so ext-calendar isn't required.

Where can I find the Hijri documentation?

Read the Hijri documentation for setup, configuration, and usage examples.

How do I report a bug or contribute to Hijri?

Open an issue or a pull request on GitHub, or ask in the Pharaonic Discord.

Ready to dig in?

Read the full documentation for installation, the day adjustment, Gregorian to Hijri and Hijri to Gregorian conversion, localized formatting, calendar validation, and real-world examples.