Keeping Time after 5pm and before 6am

Hello all,

I am brand new to UiPath. I need to extract a csv file of times that are after 5pm and before 6am into a new excel file. The csv file with the times has other information that I don’t need. I need just the times filtered. How do I go about doing this?

Hi
Any sample data or a screenshot of it and required output @matttipton12

The required output is two columns: “entry_time” after 5pm and “exit_time” before 6am

need the output in a separate excel sheet

Hi @matttipton12 ,

Could you try with the below Steps :

  1. Use Read CSV Activity, to get the Output as Datatable, let it be named as DT.

  2. We could then check with the below Expression to get the required rows as mentioned :

OutputDT = DT.AsEnumerable.Where(Function(x)CDate(x("entry_time").ToString).TimeOfDay>=TimeSpan.FromHours(17) andAlso CDate(x("exit_time").ToString).TimeOfDay<=TimeSpan.FromHours(6)).CopyToDatatable
  1. Next, we can use Filter Datatable activity to keep the required columns.
    image

Let us know if the above doesn’t work and if possible do provide us with the Sample CSV File presented.

I am not quite understanding the second step. Like I said I am very new to this.

@matttipton12 ,

It is done with an Assign activity :

L.HS. - OutputDT

R.H.S - The Expression

OutputDT = DT.AsEnumerable.Where(Function(x)CDate(x("entry_time").ToString).TimeOfDay>=TimeSpan.FromHours(17) andAlso CDate(x("exit_time").ToString).TimeOfDay<=TimeSpan.FromHours(6)).CopyToDatatable

@matttipton12 ,

Was mentioning it to be in the below manner :

The Equal to symbol is not needed as that is taken care by Assign activity.

Hi @matttipton12
Try this:

Assign Activity:
filteredDataTable = (From row In yourDataTableVar.AsEnumerable()
                     Let entryTime = DateTime.ParseExact(row("EntryTimeColumn").ToString, "h:mm tt", CultureInfo.InvariantCulture)
                     Let exitTime = DateTime.ParseExact(row("ExitTimeColumn").ToString, "h:mm tt", CultureInfo.InvariantCulture)
                     Where entryTime.Hour >= 17 And exitTime.Hour < 6
                     Select row).CopyToDataTable

Replace “EntryTimeColumn” and “ExitTimeColumn” with the actual column names that contain the entry and exit times in your DataTable
filteredDataTable is of Data Type System.Data.DataTable

Hope it helps!!

1 Like

I am not able to send attachments yet but I am still struggling. Here is the instructions on what I am supposed to do. I hope this helps a little bit.

input is the 3rd column and output is the 4th column