Skip to main content

hijri-convert

Convert dates between the Islamic (Hijri) and Gregorian calendars, in both directions, with month names in English and Arabic. Pure Python, zero dependencies.

🌐 Live demo: https://khalidt.github.io/hijri-convert/


Install

pip install hijri-convert

Use it in Python

from hijri_convert import hijri_to_gregorian, gregorian_to_hijri

hijri_to_gregorian(1413, 4, 17)
# (1992, 10, 15, 'Thursday')   ->  year, month, day, weekday

gregorian_to_hijri(1992, 10, 15)
# (1413, 4, 17, 'Thursday')

Arguments are always in the order year, month, day.

Use it from the command line

After installing, a hijri-convert command is available:

# Hijri -> Gregorian
hijri-convert --to-gregorian 17/04/1413

# Gregorian -> Hijri
hijri-convert --to-hijri 15/10/1992

# Or run with no arguments for an interactive prompt
hijri-convert

Example output:

17/04/1413 AH  (17 Rabi al-Thani 1413 / ربيع الآخر)
  =  Thursday, 15/10/1992  (15 October 1992, Gregorian)

How it works

Conversion goes through the Julian Day Number (JDN), a calendar-neutral day count, so every conversion is just:

Hijri  <->  JDN  <->  Gregorian

This uses the tabular (arithmetic) Islamic calendar.

API

Function Converts Returns
hijri_to_gregorian(y, m, d) Hijri → Gregorian (year, month, day, weekday)
gregorian_to_hijri(y, m, d) Gregorian → Hijri (year, month, day, weekday)
hijri_to_jdn(y, m, d) Hijri → Julian Day Number int
jdn_to_hijri(jdn) Julian Day Number → Hijri (year, month, day)
gregorian_to_jdn(y, m, d) Gregorian → Julian Day Number int
jdn_to_gregorian(jdn) Julian Day Number → Gregorian (year, month, day)
hijri_month_name(m, arabic=False) month number → Hijri name str
gregorian_month_name(m) month number → Gregorian name str

Hijri month names

# Name الاسم # Name الاسم
1 Muharram المحرّم 7 Rajab رجب
2 Safar صفر 8 Shaban شعبان
3 Rabi al-Awwal ربيع الأول 9 Ramadan رمضان
4 Rabi al-Thani ربيع الآخر 10 Shawwal شوّال
5 Jumada al-Awwal جمادى الأولى 11 Dhu al-Qidah ذو القعدة
6 Jumada al-Thani جمادى الآخرة 12 Dhu al-Hijjah ذو الحجة

Accuracy note

This library uses the tabular (arithmetic) Islamic calendar, which is consistent and reversible. Some countries determine month starts by moon sighting or by official almanacs such as Saudi Arabia's Umm al-Qura calendar, so a converted date may differ by ±1 day. For legal, religious, or official use, always check the relevant official calendar.


Development

git clone https://github.com/khalidt/hijri-convert
cd hijri-convert
pip install -e ".[test]"
pytest -v

License

© 2026 Khalid Alkhaldi

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).

You are free to share and adapt the material for non-commercial purposes, as long as you give appropriate credit to Khalid Alkhaldi, link to the license, and distribute any derivative work under the same license. See the LICENSE file for the full terms.

Metadata

Release files for hijri-convert 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hijri-convert 1.0.0
File Size Uploaded
hijri_convert-1.0.0.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hijri-convert 1.0.0
File Interpreter ABI Platform
hijri_convert-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / hijri_convert-1.0.0.tar.gz

Download URL hijri_convert-1.0.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2e4da4d192656a0f892e78e65c890aa1eed46b74f02ea020378c92144bc022e3
BLAKE2b-256 checksum
How to use checksums
2a1038e1483952ef58ca9ba01a40d0b9c3e7fefff4d560b700ae9cc05f2da929
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / hijri_convert-1.0.0-py3-none-any.whl

Download URL hijri_convert-1.0.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f585ce6d683dc1b750b934e65af70191f23544105191834f0735fef5f5f7f3f
BLAKE2b-256 checksum
How to use checksums
7750f88500ed870866e0947e5d4e3ab648400365f6ac8cb3a272ce9464e27c16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page