Tuesday, February 17, 2009

Convert From Georgian Date (English Date) To Arabic Hijri Date (Umm Al Qura)

I found a good question on the newsgroup answered by David Musgrave, one of the solution's steps was the conversation format between Georgian Date (Standard Date) and Hijri Date from the following link:

http://www.microsoft.com/middleeast/msdn/arabicsupp.aspx#31

Using Hijiri Calendar


You can set a culture to one of its supported calendar types. For example, the Arabic cultures support the Hijri calendar, so, you can set the Arabic culture calendar to Hijiri calendar. As mentioned before, the CultureInfo.Calendar is a read-only property which gets the current calendar, but can't be changed. Instead, you can specify the calendar of the DateTimeFormat.Calendar of the CultureInfo, as in the following code :

// Create a CultureInfo object for Saudi Arabia.
CultureInfo sa = new CultureInfo("ar-SA");
sa.DateTimeFormat.Calendar = new HijriCalendar();

You can perform any operation with Hijri dates in the same way, such as displaying Hijri and converting Hijri from/to Gregorian or other calendars.
The following example converts a date from Gregorian to Hijri and displays it:

DateTime dt;
System.Globalization.DateTimeFormatInfo HijriDTFI;
try
{
  dt = Convert.ToDateTime("12/26/2001");
  HijriDTFI = new System.Globalization.CultureInfo("ar-  EG",false).DateTimeFormat;
  HijriDTFI.Calendar = new System.Globalization.HijriCalendar();
  HijriDTFI.ShortDatePattern = "dd/MM/yyyy";
  Console.WriteLine(dt.Date.ToString("f", HijriDTFI)};
}
catch(Exception ex)
{
  Console.WriteLine(ex.Message);
}

The output is:

clip_image001

The following example converts date from Gregorian to Hijri using two different methods:

DateTime dt = new DateTime(1422, 1,1, new HijriCalendar());
Console.WriteLine(dt.Date.ToString());

The output is:
      26/11/2001 or 11/26/2001 (according to your current culture settings)

 

Hope this helps.

Regards,
--
Mohammad R. Daoud
MCP, MCBMSP, MCTS, MCBMSS
CTO
+962 - 79 - 999 65 85
Dynamics Innovations
daoudm@dynamicsinnovations.com
http://www.dynamicsinnovations.com/

2 comments:

Mohammad Daoud said...

You might also need to check Mariano Post below, he did example on this matter:

http://dynamicsgpblogster.blogspot.com/2009/02/displaying-hijri-dates-in-microsoft.html

Anonymous said...

Thanks. Explains a lot.

Related Posts:

Related Posts with Thumbnails