jacchr
September 18, 2020, 8:22am
1
Hi Experts
I have a data table with a DateTime column and I need to check if a specific date already exists in column and the return the row index.
Can this be done? I have tried using the Lookup Data Table activity but that only seems to support string values as lookup.
Any ideas?
Srini84
(Srinivas)
September 18, 2020, 8:45am
2
@jacchr
Can you share me the screen of the Data table and also format of the DateTime
Refer below post for your reference
Thanks
3 Likes
Hey @jacchr
Kindly follow the steps to achieve this:
Read your DT from Excel.
Iterate through the DT.
Use an if condition to check if the Convert.ToDateTime(row("Date"))
matches the required date and time.
If it does, you can get the index using YourDT.Rows.GetIndex(row)
.
Try it and let me know if you are facing any issues!
Cheers!
2 Likes
u322805
(Rishi)
March 18, 2023, 7:40am
4
@jacchr did you get the answer, if yes can you please share with me, thanks
@Palaniyappan can you help us please, thanks
Manish540
(Manish Shettigar)
March 18, 2023, 11:28am
5
Hi @u322805 ,
Check this sample workflow attached below,
Uipath_FindDate_GetRowIndex.xaml (10.4 KB)
Hope this may help you
1 Like
u322805
(Rishi)
March 19, 2023, 9:29am
6
@Manish540
Thanks a lot for replying, I tried but I got the below error
Am using the below expression
(From x In dt_TestReplenishment
Where DateTime.ParseExact(x(“Dato”).tostring.trim,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture) = DateTime.ParseExact( DateTime.Now.ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Select x).Any
To give you an overview My data looks like Below
I want to find the index of todays’ date in the datatable shown above and using which I will enter some data in the other cells
Manish540
(Manish Shettigar)
March 19, 2023, 11:05am
7
Hi @u322805 ,
Can you please check below code and let us know,
Var(Boolean type) = (From x In dt_TestReplenishment
Where DateTime.ParseExact(x("Dato").tostring.trim,{"MM/dd/yyyy","M/d/yyyy","MM/dd/yyyy HH:mm:ss","M/d/yyyy HH:mm:ss","dd/MM/yyyy HH:mm:ss","d/M/yyyy HH:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None) = DateTime.Now
Select x).Any
Hope this helps
Manish540
(Manish Shettigar)
March 19, 2023, 11:11am
8
Hi @u322805 ,
If you want to get the index’s of all rows of todays’ date from the datatable then use below query,
rowIndexs(Array of Int32 type) = dt_TestReplenishment.AsEnumerable.SelectMany(Function(x,i) If(DateTime.ParseExact(x("Dato").tostring.trim,{"MM/dd/yyyy","M/d/yyyy","MM/dd/yyyy HH:mm:ss","M/d/yyyy HH:mm:ss","dd/MM/yyyy HH:mm:ss","d/M/yyyy HH:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None) = DateTime.Now,{i},{})).ToArray()
Hope this may help you