Exception when Hijri Date Conversion RRS feed

  • Question



    I'm trying to parse date in string format to be DateTime format but I have exception "String was not recognized as a valid DateTime."

    Only if the date is on the last of any month like 1410/02/30.

    I can't understand what's wrong with it?


    My code is:


    Code Snippet

    redirection.CheckDate = DateTime.Parse(mtxtCheckDate.Text);



    I tried to modify it to be:

    Code Snippet

    redirection.CheckDate = Convert.ToDateTime(mtxtCheckDate.Text);



    But I still have same exception!!


    hope some one help..

    Tuesday, February 26, 2008 9:34 PM


All replies

  • From the documentation on DateTime:

    The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.)


    DateTime doesn't support Hijri dates. You need to look at the HijriCalendar class, and I believe you'll have to write your own conversion as I don't see anything in the class that will do it for you.


    Also, Safar only has 29 days, so day 30 isn't valid

    Tuesday, February 26, 2008 11:36 PM
  • Thank you for help.


    I foregot to mention that I'm using HijriCalendar by adding this code in Program.cs:

    Code Snippet

    Application.CurrentCulture = CultureInfo.GetCultureInfo("ar-SA");



    And that changed the culture to Saudi Arabia culter and we using Hijri calendar in saudi arabia..



    Also, Safar only has 29 days, so day 30 isn't valid



    No, Hijri month`s days selected by moon. If the moon is shown in last of month the month is 30 if not month is 29!


    Qutation From ME MSDN

    Overview of the Hijri Calendar

    The Hijri calendar is based on the motion of the moon around the earth, and therefore lunar, while the Georgian calendar is based on the motion of the earth around the sun, and therefore solar. The Hijri calendar’s reference point is the Hijra (migration) of the prophet form Mecca to Medina. The start date of the calendar was chosen to be the first day of the first Arabic months (Muharram) of the year of the Hijra. The Hijri calendar is composed of 12 months, however, the Hijri year is shorter than the solar (Gregorian) year with around 11 days. Therefore the Islamic occasions do not always start in the same seasons, on every solar year.

    The Hijri calendar is the official calendar in many Islamic countries in the Gulf region and especially Saudi Arabia. Other Arab countries use the Hijri calendar along side the Georgian calendar. Therefore the support of the Hijri calendar was imperative to the usefulness of Microsoft products in these cultures.



    Best Regards...

    Wednesday, February 27, 2008 7:10 AM
  • According to the documentation for C#, Safar only has 29 days in the HijriCalendar Smile

    Wednesday, February 27, 2008 8:43 AM
  • So it's wrong in .NET !



    Okay, Thanks for your help, I think I will make my HijriCalendar Class !




    Wednesday, February 27, 2008 9:09 AM