Converting+Islamic+dates

//by Richard Russell, August 2015//

The code below shows how to convert between Western (Gregorian) and Islamic (Hijri) dates; it requires Windows Vista or later:

code format="bb4w" year% = 2015 : month% = 8 : day% = 14

PROC_GregorianToHijri(year%, month%, day%) PRINT year%, month%, day%

PROC_HijriToGregorian(year%, month%, day%) PRINT year%, month%, day%

END

DEF PROC_GregorianToHijri(RETURN year%, RETURN month%, RETURN day%) LOCAL cdt{}, st{} : CAL_HIJRI = 6 DIM st{wYear{l&,h&}, wMonth{l&,h&}, wDayOfWeek{l&,h&}, wDay{l&,h&}, \ \  wHour{l&,h&}, wMinute{l&,h&}, wSecond{l&,h&}, wMilliseconds{l&,h&}} DIM cdt{CalId%, Era%, Year%, Month%, Day%, DayOfWeek%, Hour%, Minute%, \ \  Second%, Tick%} st.wYear.l& = year% : st.wYear.h& = year% >> 8 st.wMonth.l& = month% : st.wDay.l& = day% SYS "ConvertSystemTimeToCalDateTime", st{}, CAL_HIJRI, cdt{} year% = cdt.Year% : month% = cdt.Month% : day% = cdt.Day% ENDPROC

DEF PROC_HijriToGregorian(RETURN year%, RETURN month%, RETURN day%) LOCAL cdt{}, st{} : CAL_HIJRI = 6 DIM st{wYear{l&,h&}, wMonth{l&,h&}, wDayOfWeek{l&,h&}, wDay{l&,h&}, \ \  wHour{l&,h&}, wMinute{l&,h&}, wSecond{l&,h&}, wMilliseconds{l&,h&}} DIM cdt{CalId%, Era%, Year%, Month%, Day%, DayOfWeek%, Hour%, Minute%, \ \  Second%, Tick%} cdt.Year% = year% : cdt.Month% = month% : cdt.Day% = day% cdt.CalId% = CAL_HIJRI : cdt.Era% = 1 FOR cdt.DayOfWeek% = 1 TO 7 SYS "ConvertCalDateTimeToSystemTime", cdt{}, st{} NEXT year% = st.wYear.l& + 256*st.wYear.h&     month% = st.wMonth.l& : day% = st.wDay.l&      ENDPROC code Note that, depending on the time of day and the location, there may be some ambiguity in the conversion so don't be surprised if these routines give a result which is a day or so different from that obtained from other calculators.