Blog

Microsoft Dynamics AX Blog

3

Convert All Hirji Formats into Gregorian

I came across a requirement where I needed to convert users entry from Hirjri Calendar date (the Islamic Calendar) into the Gregorian Calendar. In previous posts, I have shown how to convert Gregorian Date (date data type in Dynamics AX) into Hirjri… if you are interested in those check them out here:

In order to convert a Hirji date into Gregorian, I used the .NET classes referenced in the any Dynamics AX standard version.

Enjoy!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Amer Atiyah, http://blog.amerax.net
static date hijri2GrDate(DAPHijridateStr   hijriDateStr)
{
    System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
    System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US");
    System.DateTime                  tempDateTime;
    str                              strTemp;
    System.String[]                  arr;
    date                             grDate;
;
 
    //all expected dates formats
    arr = new System.String[18]();
    arr.SetValue("dd M yyyy",  0);
    arr.SetValue("yyyy/MM/dd",  1);
    arr.SetValue("yyyy/M/d",    2);
    arr.SetValue("d/M/yyyy",    3);
    arr.SetValue("dd/MM/yyyy",  4);
    arr.SetValue("yyyy-MM-dd",  5);
    arr.SetValue("d/MM/yyyy",   6);
    arr.SetValue("dd/M/yyyy",   7);
    arr.SetValue("yyyy-M-d",    8);
    arr.SetValue("dd-MM-yyyy",  9);
    arr.SetValue("yyyy MM dd",  10);
    arr.SetValue("d-M-yyyy",    11);
    arr.SetValue("d-MM-yyyy",   12);
    arr.SetValue("dd-M-yyyy",   13);
    arr.SetValue("d M yyyy",    14);
    arr.SetValue("dd MM yyyy",  15);
    arr.SetValue("yyyy M d",    16);
    arr.SetValue("d MM yyyy",   17);
 
    try
    {
        tempDateTime = System.DateTime::ParseExact(hijriDateStr, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces);
    }
    catch
    {
        error("Unexpected Hirji date format.");
        return datenull();
    }
    strTemp = tempDateTime.ToString("dd/MM/yyyy");
    grDate = str2date(strTemp, 123);
 
    return grDate;
}

It might a great idea if you added this method to the “Global” class, like what I did :).

Hirji into Gregorian

Dynamics AX 2012 Event

Recent Posts

Tags

Archives

Random Testimonial

  • ~ Mohamad Adel, Sr. Dynamics AX Developer at Al-Fanar IT

    Adel"I recommend Amer Atiyah as i worked with him in many simple and complicated tasks and i realized that he is very intelligent in the way of thinking to solve tasks problems. He has a very good experience and knowledge of his job. He is very hard worker, committed, organized and creative and very open mind in his work and that is the reason if his brilliant in his specialized field. He is always showing a high degree of professionalism and ability to deliver and accomplish very complicated tasks at any condition with high quality. I am recommending him to work in any team and i know he will fit with all challenges. Purely, he is a professional guy. I wish to him more and more success in his career and his life."

  • Read more testimonials »