Error getting min value for data time from data table

Hi All, I am trying to execute below to get minimum value from a data table and getting an error. Might be something simple but would love to get your input on how to solve it.

Assign Activity:
ExtractDataTableDetails.AsEnumerable().Min(Function (drRows) DateTime.Parse(drRows.Item(2).ToString)).ToString

Source: Assign

Message: The string ‘09/27/2022 08:02:02.797 A.M.’ was not recognized as a valid DateTime. There is an unknown word starting at index ‘24’.

@Mchande

Please try this

ExtractDataTableDetails.AsEnumerable().Min(Function (drRows) DateTime.ParseExact(drRows.Item(2).ToString.Replace("A.M.","AM").Replace("P.M.","PM").Trim,"MM/dd/yyyy hh:mm:ss.fff tt",System.Globalization.CultureInfo.InvariantCulture)).ToString

Cheers

Hi @Anil_G - Thank you for replying. Now getting an error.

Source: Assign

Message: String ‘’ was not recognized as a valid DateTime.

@Mchande

You have empty string in the column I guess use as below…

ExtractDataTableDetails.AsEnumerable().Min(Function (drRows) If(String.IsNullOrEmpty(drRows.Item(2).ToString.Trim),Now,DateTime.ParseExact(drRows.Item(2).ToString.Replace("A.M.","AM").Replace("P.M.","PM").Trim,"MM/dd/yyyy hh:mm:ss.fff tt",System.Globalization.CultureInfo.InvariantCulture))).ToString

Cheers

1 Like

Thank you @Anil_G . That helped!

1 Like

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