Convert Gregorian Date to Hijri (Hegira, Islamic Calendar) Date

I want to convert the date into google sheet

Ahmad_1_1-1659239784060.png

 

1 2 2,484
2 REPLIES 2

Looks like https://youtu.be/tbGZudBLNAk might have a solution for this? Maybe?

Hope this helps, at least a little,

Ian

  1. Get API Key from Aladhan:

    • Visit the Aladhan API website (URL Removed by Staff) and sign up for an API key.
  2. Enable Google Apps Script:

    • Open your Google Sheet.
    • Click on "Extensions" in the menu.
    • Choose "Apps Script."
    • Paste the following code into the script editor:

      function CONVERT_TO_HIJRI(date) {
      var apiKey = 'YOUR_ALADHAN_API_KEY';
      var apiUrl = 'https://api.aladhan.com/v1/gToH?';

      var formattedDate = Utilities.formatDate(date, 'GMT', 'yyyy-MM-dd');
      var response = UrlFetchApp.fetch(apiUrl + 'date=' + formattedDate, {
      headers: {
      'X-API-Key': apiKey
      },
      });

      var data = JSON.parse(response.getContentText());

      if (data.status === 'OK') {
      return data.data.hijri.date;
      } else {
      return 'Error converting date';
      }
      }


      Replace 'YOUR_ALADHAN_API_KEY' with the API key you obtained from Aladhan.
    • Save the script:

      • Click on the floppy disk icon or press Ctrl + S to save the script.
    • Use the function in your sheet:

      • Now, you can use the CONVERT_TO_HIJRI function in your Google Sheet to convert a Georgian date to the Hijri date. For example, if the Georgian date is in cell A1, you can use the formula in another cell like this: