web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to Fix Hijri Date Inaccuracy in D365 F&O and SSRS

(1) ShareShare
ReportReport
Posted on by 405

Hello everyone,

I'm facing an issue with Hijri dates in D365 F&O.

The problem first occurred when I created a "Display Method" for the first time using this code:

    public static str ConvertToHijri(TransDate _TransDate)
    {
        TransDate           dateTime = _TransDate;
        CalendarConverter   calendarConverter = new CalendarConverter(PreferredCalendar::Hijri);
        int                 hijriDay;
        int                 hijriMonth;
        str                 hijriYear, finalHijriDate;
        str                 hijriDayStr, hijriMonthStr, hijriYearStr;


        hijriDay            = calendarConverter.dayofmth(dateTime);
        hijriMonth          = calendarConverter.mthofyr(dateTime);
        hijriYear           = calendarConverter.yearStr(dateTime);


        hijriDayStr         = int2str(hijriDay);
        hijriMonthStr       = int2str(hijriMonth);
        hijriYearStr        = hijriYear;


        finalHijriDate      = hijriYearStr + '/' + hijriMonthStr + '/' + hijriDayStr;
        return finalHijriDate;
    }

As you can see, this code had an issue where it advanced the date by one day. For example, the date 2024/11/17 returns as 1446/5/16, which is somewhat incorrect, as the correct corresponding date is 1446/5/15.

I resolved the issue by changing the code from "PreferredCalendar::Hijri" to "PreferredCalendar::UmAlQura" , and it worked; the date now correctly returns as 1446/5/15.

Now, I am facing the same issue in SSRS reports. I followed the steps in this question: How to convert date from gregorian to hijri in SSRS report?

I changed the Calendar property to Hijri, and when I ran the report, I encountered the same issue of shifting the date forward by one day, such as the 2024/11/17 Gregorian date.

I tried solutions like adding a new column to the report table LedgerTransStatementTmp, but I found that the class LedgerTransStatementDP is somewhat complex, and I couldn’t figure out where to add the value for the field I added to the table.

I hope you can help me with this problem, and thank you for your time.

Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    First of all, let me simplify your code a little bit, to make it easier to work with.
    public static str convertToHijri(TransDate _transDate)
    {
        CalendarConverter calendarConverter = new CalendarConverter(PreferredCalendar::Hijri);
    
        return strFmt('%1/%2/%3',
            calendarConverter.dayOfMth(_transDate),
            calendarConverter.mthOfYr(_transDate),
            calendarConverter.yearStr(_transDate));
    }
    You seem to be saying that Are you saying that new CalendarConverter(PreferredCalendar::Hijri).dayOfMth(mkDate(17,11,2024)) always gives 16 (and all the other code can be ignored). Is it so? If this gives you the correct result but your code doesn't, then _transDate probably contains something else then you think.
     
    Later I'll check what I get when I run it.
  • Verified answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    I tried the code and got 16 from dayOfMth(), as you said. And I agree it should be 15.
     
    This suggests that there may be a bug in dayOfMth() that you should address by creating a support request.
     
    But it may be worth digging deeper to the implementation. I'm not familiar with the logic of the conversion, but I've noticed that documentation of HijriCalendar says:
     
    This implementation of the HijriCalendar class adjusts the calendar date by adding or subtracting a value from zero to two days to accommodate the variances in the start and the end of Ramadan and to accommodate the date difference between countries/regions. That value is stored in the HijriAdjustment property. If HijriAdjustment is not set explicitly, it derives its value from the settings in the regional and language options portion of Control Panel and is stored in the registry value HKEY_CURRENT_USER\Control Panel\International\AddHijriDate. However, that information can change during the life of the AppDomain. The HijriCalendar class does not detect changes in the system settings automatically.
     
    Maybe it's relevant to the problem and HijriAdjustment should be set differently.
  • Ali AbdAlNasser Profile Picture
    405 on at
    Hello Martin Dráb.  
    I am happy to receive a response from you to my question.
    You can get the correct date if this code is used:  
     
    public static str convertToHijri(TransDate _transDate)
    {
        CalendarConverter calendarConverter = new CalendarConverter(PreferredCalendar::UmAlQura);
    
        return strFmt('%1/%2/%3',
            calendarConverter.dayOfMth(_transDate),
            calendarConverter.mthOfYr(_transDate),
            calendarConverter.yearStr(_transDate));
    }
     
     
    And this is what I am trying to achieve: how can I get the same output in an SSRS report?
  • Ali AbdAlNasser Profile Picture
    405 on at
    Hello Martin Dráb.  

    From what I understood from your response to my question, I need to adjust the HijriAdjustment property.  
    How can I specifically adjust the HijriAdjustment property? Is there a direct way to modify it within the code or from the system settings? I would appreciate your clarification. Thank you for your help!
  • Verified answer
    Ali AbdAlNasser Profile Picture
    405 on at
    Hello Martin Dráb.

    Thank you for your help. I carefully considered your response and realized the solution to the problem, and now it is working correctly. All I did was go to Control Panel > Region > Additional settings, then go to the Date list and change the Calendar type to "Umm al-Qura."

    And that solved my problem.

    Thank you for your help.
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    I played a bit with code it seems that you really have to use UmAlQuraCalendar to get the expected result. HijriAdjustment isn't a solution, because it adjusts the number in the wrong direction.
     
    For reference, here is a piece of code demonstrating both calendars for the date time format.
    System.DateTime dateTime = new System.DateTime(2024, 11, 17);
    
    CultureInfo culture1 = new CultureInfo('ar-SA', false); // Uses UmAlQuraCalendar
    CultureInfo culture2 = new CultureInfo('ar-SA', false);
    
    // Use HijriCalendar
    HijriCalendar hijriCalendar = new HijriCalendar();
    hijriCalendar.HijriAdjustment = 2;
    DateTimeFormatInfo dateTimeFormat = culture2.DateTimeFormat;
    dateTimeFormat.Calendar = hijriCalendar;
            
    str s1 = dateTime.ToString('dd', culture1.DateTimeFormat);
    str s2 = dateTime.ToString('dd', culture2.DateTimeFormat);
    By the way, CalendarConverter always uses the CultureInfo object for ar-SA, i.e. Saudi Arabia.
  • Ali AbdAlNasser Profile Picture
    405 on at
    Hello Martin Dráb.

    First, I wanted to thank you for helping me find the solution. Above all, I wanted to mark your response as "answer verified," but it seems there is an issue on my end and I can't do that. So, I hope you can mark it as verified instead of me so everyone can benefit.
    Thank you for your response.
     
    Thank you for your help.
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    You're welcome.
     
    It's not your fault that you can't mark the verified answer; there is a bug on this site that often prevents it. It usually works better for me (as a moderator).
  • Verified answer
    Ali AbdAlNasser Profile Picture
    405 on at
    Hello everyone.

    I have found a better solution for selecting the Hijri date for UmAlQura in the SSRS report.
     
    Just set this format ="UmAlQura" and everything will work fine.

    I hope this solution is suitable for everyone as it does not require you to change the date settings in the client environment.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans