File Exchange

image thumbnail

Date Converter: Gregorian, Persian, and Islamic calendars

version 2.1.0.1 (8.39 KB) by Omar Joya
Converts dates across Gregorian, Persian/ Jalali (Solar Hijri), and Islamic Lunar Hijri calendars

6 Downloads

Updated 28 Oct 2019

View License

dateconv(Y,M,D,from_calend,to_calend) computes bilateral date conversion between Gregorian Common Era ('ce'), Persian Solar Hijri or Jalali ('sh'), and Islamic Lunar Hijri ('lh') calendars. Outputs a 1x3 numeric array vector of [Y,M,D], and a character array with printed date with month names in Persian, Arabic, or English. For Persian and Islamic calendars, the numbers are shown in Eastern Arabic numerals.
For example:
[outdatenum,outdatetxt] = dateconv(2000,1,1,'ce','sh') returns the equivalent date for Jan 1, 2000 in Persian Solar Hijri calendar:
outdatenum = [1378,10,11]
outdatenum = ۱۱ دی/جدی ۱۳۷۸
Conversion takes place through the Julian Day Number. Each calendar is converted to and computed back from the Julian Day Number.

For Gregorian calendar, the algorithm by NASA/Goddard is adopted, which correctly computes the dates for Proleptic era (before 1582).

For Persian/ Jalali calendar, the algorithm is based on the method proposed by Musa Akrami (2014) and implemented by Soroush Rabiei (2017).

Check & tests:
The start of the Persian calendar epoch (1/1/475 SH) per Akrami's 2,820 years cycle starts on Mar 15, 1096 (and NOT on March 21st as other date converter algorithms suggest):
dateconv(475,1,1,'sh','ce'): ans = [1096,3,15]
The first day of the Persian calendar starts on Mar 19, 622:
dateconv(1,1,1,'sh','ce'): ans = [622,3,19]
The first day of the Islamic Lunar Hijri starts on July 15, 622:
dateconv(1,1,1,'lh','ce'): ans = [622,7,15]

Cite As

Omar Joya (2020). Date Converter: Gregorian, Persian, and Islamic calendars (https://www.mathworks.com/matlabcentral/fileexchange/67221-date-converter-gregorian-persian-and-islamic-calendars), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Omar Joya

Hi Daniele, thanks for the bringing the issue up. The discrepancy arose from Islamic Lunar Hijri conversion to Julian Day Number. I recall that the algorithm treats the start of the day for Islamic Lunar Hijri at the sunset of the eve of a given day in Gregorian Calendar, hence the 1-day difference you noticed. I fixed the algorithm, now it should be fine.

Hi Omar,

thank you for your interesting contribution. However I've noticed the following:
>> dateconv(2019,8,11,'ce','lh')
ans = 1440 12 10
>> dateconv(1440,12,10,'lh','ce')
ans = 2019 8 12
In other words, converting a date from Gregorian system and Lunar Hijiri and then convert back to Gregorian the resulting date does not give you the original Gregorian date.
Regards

Updates

2.1.0.1

Fixed conversion issue from Islamic Lunar Hijri to Gregorian calendar

2.1.0.0

Fixed conversion issue from Islamic Lunar Hijri to Gregorian calendar

2.0.0.0

Added the feature to show printed date with month names in Persian, Arabic, or English. For Persian and Islamic calendars, the numbers are shown in Eastern Arabic numerals.

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux