Click here to Skip to main content
15,915,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if i convert the below Arabic date to English then i will face an exception(String was not recognized as a valid DateTime) .Please suggest if any solution for this.

If i am doing same in google converter then i got the answer in google is: 27 January, 2009 Tuesday

But i want to do in c# coding can you please help me??

arabic date formate is : (1430/01/30 yyyy/mm/dd)

What I have tried:

C#
private void ConvertArabicDate()
        {
            string strArabicDate="14300130";
            string engDate = string.Empty;
            CultureInfo arCul = new CultureInfo("ar-SA");
            CultureInfo enCul = new CultureInfo("en-US");
            string[] allFormats = { "yyyy/MM/dd", "yyyy/M/d", "dd/MM/yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "yyyy-MM-dd", "yyyy-M-d", "dd-MM-yyyy", "d-M-yyyy", "dd-M-yyyy", "d-MM-yyyy", "yyyy MM dd", "yyyy M d", "dd MM yyyy", "d M yyyy", "dd M yyyy", "d MM yyyy" };
            try
            {

                DateTime tempDate = DateTime.ParseExact(strArabicDate, allFormats, arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
                engDate = tempDate.ToString("dd-MMM-yyyy", enCul.DateTimeFormat);
            }
            catch (Exception ex)
            {
                 
               
                    engDate = "Unable to convert Arabic date ";
               
            }
        }
Posted
Updated 25-Oct-16 4:33am
v3
Comments
Member 12664955 25-Oct-16 11:43am    
Sorry All formats array first one contain yyyymmdd it taken in to array . can you please check once and provide any solution

1 solution

You're very close but your input string format does not match any of your allFormats formats.

You have the date in "yyyyMMdd" which does not appear in the array.

Other than that, it all looks fine
 
Share this answer
 
Comments
Member 12664955 25-Oct-16 11:41am    
Sorry in allFormats array first one is the yyyymmdd has taken in array . please check once the code and provide the solution
Member 12664955 26-Oct-16 0:15am    
Hi Andy we have checked the array now it added to allFormat array at 0 index position is yyyyMMdd but these format also we face an exception please help me

Any one can add the solution to above question please.
Andy Lanng 26-Oct-16 8:55am    
is there a new exception, or the same one?
Member 12664955 27-Oct-16 6:18am    
same exception

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900