Assign: String '11/1/2022 12:00:11 AM' was not recognized as a valid DateTime

Hello Everyone:
I am trying to sort datatable through column which contains data like this and I am getting this Error.

I am using query :slight_smile:
->(From d In DT.AsEnumerable
Group d By d(“Col1”).ToString.Trim Into grp=Group
Select R=grp.OrderBy(Function (r) DateTime.ParseExact(r(“Date”).ToString,“dd/MM/yyyy hh:mm:ss”, System.Globalization.CultureInfo.InvariantCulture)).First()).CopyToDataTable

Hi @raja.arslankhan ,

You would need to use Multiple date time formats for parsing. You could check the below posts on how to use the DateTime.ParseExact() with Multiple formats.

You could modify the DateTime.ParseExact() in your expression accordingly

As Excel displayed values can differ from the late stored values within the DT after read range it is also recommended to check the Datatable. Find some techniques for this here:
:ambulance: :sos: [FirstAid] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues - News / Tutorials - UiPath Community Forum


or more control as described in the FirstAid with ParseExact and maybe along with a date format array

Also Cross Reference:


According to display the format should be "d/M/yyyy h:m:s tt"

and as mentioned by @ppr it is worth checking the data after reading…generally it might be little different


Problem solved.


1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.