Check if date exists in data table and return row index if true

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?

@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 :wave:

Kindly follow the steps to achieve this:

  1. Read your DT from Excel.
  2. Iterate through the DT.
  3. Use an if condition to check if the Convert.ToDateTime(row("Date")) matches the required date and time.
  4. 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

@jacchr did you get the answer, if yes can you please share with me, thanks
@Palaniyappan can you help us please, thanks

Hi @u322805 ,

Check this sample workflow attached below,
Uipath_FindDate_GetRowIndex.xaml (10.4 KB)

Hope this may help you :slight_smile:

1 Like

@Manish540
Thanks a lot for replying, I tried but I got the below error

image

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

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 :slight_smile:

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 :slight_smile: