I have a specific workflow to get the date format from a column in an excel file >> the problem is I can’t know the date format some of these excel files will be in Arabic time like “2022-04-29 12:00:13 ص”, I tried a lot of formats but still give an error in recognizing the valid DateTime format… I want a way to find all “ص” OR “م” in the whole column and replace them with “AM” or “PM”…
But this is not the all problem because this excel file is different each time and will contain different DateTime formats !! like this “4/29/2022 1:00”
How to make get DateTime format dynamic so that whatever the excel file is contained in the date column will convert it to what I want !!!
that’s what I’m using to convert the given DateTime format to a specific one:
DateTime.ParseExact(posting_date.Tostring,{"MMM dd, yyyy","MMM d, yyyy","MMM d, yyyy hh:mm tt","MMM dd, yyyy hh:mmtt"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd HH:mm:ss")
You can any date format based on needing here -> {"MMM dd, yyyy","MMM d, yyyy","MMM d, yyyy hh:mm tt","MMM dd, yyyy hh:mmtt"}
but non of these formats work with this DateTime ‘2022-04-29 12:00:13 ص’ !! I tried to add this format also “yyyy-MM-dd hh:mm:ss t” but still given the same error “Assign - posting date: String ‘2022-04-29 12:00:13 ص’ was not recognized as a valid DateTime.”
If you need to use various formats Try this expresssion give your required format at the end of the expression inside .ToString(“Your required formats”)
I’m so appreciative of your fantastic help the problem has been solved as I want exactly what @Gokul_Jayakumar posted as the best solution for my scenario.
Sorry to take a long time to reply to you because I was trying all the solutions you mentioned.