Hi
I have a datatable read from an excel file. One of the column say “A” sometimes contains a statement and sometimes date along with time stamp. Some operations are done on this DataTable and a new DatatTable is written in the new sheet. If Column A contains date it should take only date not the timestamp. If it contains statement let it take as statement only. How do I achieve this.
I used below syntax;
If(DateTime.TryParse(text, Nothing), CDate(text).ToString(“MM/dd/yyyy”),text)
but suggest w.r.t changing for entire column of the DataTable
Before reading the excel file
Assuming you have control over the input file - With UiPath / Manually (Whichever works for you) - create a new column in excel with the required date format(removing time stamp) only and use formula “=A2”. This will change based on your input
After the above change - read the excel file and use new column in the data table keeping the old one as it is
Let us know if this solution is not applicable for you
Hi Thanks for the suggestion, but can you suggest alternate way using DataTable Operations rather than excel
I think this should work. But Clone the DataTable. here dt2 is cloned from dt
(From row In dt
Let a=row(“FN”).ToString
Let b=row(“LN”).ToString
Let c=row(“Date”).ToString
Let x=New Object(){a,b,If(DateTime.TryParse(c,Nothing),CDate(c).ToString(“MM/dd/yyyy”),c)}
Select dt2.Rows.Add(x)).CopyToDataTable