Setting Data table column type

Hi,
I need to set data table column “EventDate” type like “Thu 03-17-22” . I am trying to use the following code

dt.AsEnumerable().ToList().ForEach(Sub(row) row(“EventDate”) = Convert.ToDateTime(row(“EventDate”).ToString.Trim).ToString(“dd dd-MM-yyyy”)).

It is throwing me an error. Can you help? Thanks much,

Hi,

Which activity do you use? In UiPath, we need to use the expression in InvokeCode activity as the following.

Sample:

Main.xaml (7.6 KB)

Regards,

Yes, I am using Invoke code. The data table column has data in the format dd/mm/yyyy hh:mm. I need to show it as “Day dd-mm-yyyy”

Thanks,

Hi

Try mentioning like this with Datetime.ParseExact

dt.AsEnumerable().ToList().ForEach(Sub(row) row(“EventDate”) = Datetime.ParseExact(row(“EventDate”).ToString.Trim.SubString(0,10), “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd dd-MM-yyyy”))

Cheers @cury

Hi,

Can you try the following expression in InvokeCode?

Convert DateTime :

dt.AsEnumerable().ToList().ForEach(Sub(row) row("EventDate") = DateTime.ParseExact(row("EventDate").ToString.Trim,"dd/MM/yyyy HH:mm",System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”))

OR

String manipulation :

dt.AsEnumerable().ToList().ForEach(Sub(row) row("EventDate") = row("EventDate").ToString.Trim.Substring(0,10).Replace("/","-"))

Regards,

Getting the following…
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.FormatException: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.

Convert to Date Time:

RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)

String Manipulation: Giving no errors but keeping the format as “dd/mm/yyyy”

Thanks,

You don’t need to use Invoke Code. You can use the dt.AsEnumerable… in an Assign.

Hi,

If possible, can you share your workflow and input data as file?

Regards,