cury
March 20, 2022, 9:59pm
1
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,
Yoichi
(Yoichi)
March 20, 2022, 11:30pm
2
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,
cury
March 21, 2022, 1:26am
3
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
Yoichi
(Yoichi)
March 21, 2022, 11:35am
5
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,
cury
March 21, 2022, 8:39pm
6
Palaniyappan:
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”))
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.
cury
March 21, 2022, 8:47pm
7
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)
cury
March 21, 2022, 9:09pm
8
String Manipulation: Giving no errors but keeping the format as “dd/mm/yyyy”
Thanks,
postwick
(Paul Ostwick)
March 21, 2022, 9:26pm
9
You don’t need to use Invoke Code. You can use the dt.AsEnumerable… in an Assign.
Yoichi
(Yoichi)
March 21, 2022, 11:20pm
10
Hi,
If possible, can you share your workflow and input data as file?
Regards,