Hi everyone!
i need to convert a column of string(such as “25/08/20”,“15/08/20”,“17/07/20”) from a datatable to datetime formats without loop inside datatable.
i have a problem with this assign:
(From row In Compressed2 let dt= convert.ToDateTime(DateTime.ParseExact(row.Item(“Column2”).ToString,“dd/MM/yy”,Globalization.CultureInfo.InvariantCulture)) Select row).CopyToDataTable
nothing happens with this expression… Help Me Please!!
@Angelo_Savino
In General the LINQ Syntax should/could look like following
(From row In Compressed2.AsEnumerable
Let dt= DateTime.ParseExact(row.Item(“Column2”).ToString,“dd/MM/yy”,Globalization.CultureInfo.InvariantCulture)
Select row).CopyToDataTable
AsEnumerable is used for bringing the rows into an enumerable sequence
There is no need to parseString into datetime (ParseExact Method) and then convert a datetime into a dateTime (Conver.toDate)
But this statement will not do any changes. the Let part stores the converted dateinfo as like a temporary variable, but will not not do any modifications. So the unedited row will be iterated (From In … is same like a for each iteration) and copy it to a datatable.
It looks like you tried to modifiy the datacolumn. This can be done in LINQ with converting and reconstructing the itemArray from row. The modified ItemArray can be used for adding a new row e.g. to an empty cloned datatable.
But updating column with a LINQ within an assign will not work.
Start to do it with a for each, check if the reconstruct the empty datatable approach will work for you. Last resort could be invoke code activity
@Angelo_Savino - any reason why you’re againstusing a loop inside the datatable? Using LINQ is still going to iterate through the whole datatable, so why not just make it easy on yourself by doing the following:
Add data column - this will be where you put the new datetime column in your existing datatable. I’ll name this row “NewColumn” but you should name it whatever you want
For each row in Compressed2
Assign row.item(“NewColumn”) = DateTime.ParseExact(row.item(“Column2”).ToString,“dd/MM/yy”,Globalization.CultureInfo.InvariantCulture)
next row
Remove Data column - remove the old string column from the existing datatable
Super easy to understand what you’re doing and it can be done in 3-4 activities. It should be extremely fast as well, as it is just doing a single loop through your datatable
thanks for you contribute, I am use your provide activity package aways. it`s nice. I have problem now. when I useing Datetime ParseTo Datatbl then alert error:“DateTime ParseTo Datatable : String was not recognized as a valid DateTime”. Datetime formmat is “12/2/2021 3:27:11 AM”, type is string. can you help me?
Hello Sir @balupad14 …I sincerely thank your efforts for creating a new set of activities. But I am not able to get the desired results.
I want to read the date of the form (YYYY-MM-DD) from one csv file and write it into an excel sheet in the same format. After I read the date through UiPath,when I try to write to excel, it is writing it in (MM-DD-YYYY) format
I used your “DateTime Parse To Datatable” activity. But I get the following error.
But you mentioned that it can also convert strings into the desired format.
Hello sir, As .csv format is not allowed to share here, i converted the “list1” to excel and shared.
My aim is to read data from list1 file and write to “New” excel file in the same format.
YYYY-MM-DD. But the date in the “New” file is coming in the format MM/DD/YYYY.