User Tools

Site Tools


Islamic calendar conversion (LBB)

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:

      CAL.HIJRI = 6
      global CAL.HIJRI
      struct SYSTEMTIME, wYear as word, wMonth as word, _
        wDayOfWeek as word, wDay as word, wHour as word, _
        wMinute as word, wSecond as word, wMilliseconds as word
      struct CALDATETIME, CalId as long, Era as long, _
        Year as long, Month as long, Day as long, DayOfWeek as long, _
        Hour as long, Minute as long, Second as long, Tick as long
      year = 1952 : month = 5 : day = 3
      call GregorianToHijri year, month, day
      print year, month, day
      call HijriToGregorian year, month, day
      print year, month, day
  sub GregorianToHijri byref year, byref month, byref day
      SYSTEMTIME.wYear.struct = year
      SYSTEMTIME.wMonth.struct = month
      SYSTEMTIME.wDay.struct = day
      calldll #kernel32, "ConvertSystemTimeToCalDateTime", _
        SYSTEMTIME as struct, CAL.HIJRI as long, _
        CALDATETIME as struct, result as long
      year = CALDATETIME.Year.struct
      month = CALDATETIME.Month.struct
      day = CALDATETIME.Day.struct
  end sub
  sub HijriToGregorian byref year, byref month, byref day
      CALDATETIME.Year.struct = year
      CALDATETIME.Month.struct = month
      CALDATETIME.Day.struct = day
      CALDATETIME.CalId.struct = CAL.HIJRI
      CALDATETIME.Era.struct = 1
      for dow = 1 to 7
        CALDATETIME.DayOfWeek.struct = dow
        calldll #kernel32, "ConvertCalDateTimeToSystemTime", _
          CALDATETIME as struct, SYSTEMTIME as struct, _
          result as long
      year = SYSTEMTIME.wYear.struct
      month = SYSTEMTIME.wMonth.struct
      day = SYSTEMTIME.wDay.struct
  end sub

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.

islamic_20calendar_20conversion_20_28lbb_29.txt · Last modified: 2018/04/17 16:44 by tbest3112