Start Date with in the 4 days


I need,

Start Date End Date
09-05-2022 15-05-2022
30-04-2022 15-05-2022
15-04-2022 15-04-2022
01-05-2022 15-05-2022

We have to filter and get a count of date when the Start date is within 4days. and End date is greater than current date.

1 Like

You can use filter datatable activity and pass the necessary condition.
You will get a filtered datatable and then we can use datablename.rows.count to get the count

Hi there @ShekharRPA,
I hope you are well!

You should be able to use the below:
Assign intCount = dtExample.AsEnumerable().Count(Function (drRow) DateTime.Now.AddDays(4) >= DateTime.Parse(drRow.Item("Start Date").ToString) AND DateTime.Parse(drRow.Item("End Date").ToString) > DateTime.Parse(drRow.Item("Start Date").ToString))

This should count those that:

  • Today is 4 days or less away from Start Date.
  • End Date is greater than Start Date.

Let me know if you require further clarification!
Thanks once again,

But condition is,No count will be consider if start date is less than Current date. So We will get 1 count as per input i provided.

Hi there @ShekharRPA,
Understood, so only count those where today is greater than Start Date, up to 4 days?

If so, the below should work:
Assign - intCounter = dtExample.AsEnumerable().Count(Function (drRow) DateTime.Now > DateTime.ParseExact(drRow.Item("Start Date").ToString, "dd-MM-yyyy", Nothing) AND DateTime.Now <= DateTime.ParseExact(drRow.Item("Start Date").ToString, "dd-MM-yyyy", Nothing).AddDays(4) AND DateTime.ParseExact(drRow.Item("End Date").ToString, "dd-MM-yyyy", Nothing) > DateTime.ParseExact(drRow.Item("Start Date").ToString, "dd-MM-yyyy", Nothing))

Please let me know your thoughts.
Thanks once again,

Error Assign: String was not recognized as a valid DateTime.

Hi @ShekharRPA ,

You can try this with Linq , I believe this would solve the purpose

Condition formatted as StartDate > Today AND StartDate <= Today + 4 AND EndDate > Today

DateTime.Parse(x("StartDate").tostring) >= DateTime.Now      
DateTime.Parse(x("StartDate").tostring) <= DateTime.Now.AddDays(4)             
DateTime.Parse(x("EndDate").tostring) > DateTime.Now).Count

Processing exception “)”

Hi @ShekharRPA ,

Could you try with the Below Expression :

dt.AsEnumerable.Where(Function(x) DateDiff(DateInterval.Day,CDate(x("StartDate").tostring),DateTime.Now)>0 andAlso DateDiff(DateInterval.Day,CDate(x("StartDate").tostring),DateTime.Now)<=4 AndAlso CDate(x("EndDate").tostring) > DateTime.Now).Count

Could you also let us know if there would be Empty values as well ?

If the Expression gives out an Error, Could you Print one value using a Write Line Activity to just Check the Date format.

This could have happened due to date being in dd-MM-yyyy format

corrected the linq as

DateTime.ParseExact(x(“SD”).ToString, “dd-MM-yyyy”, Nothing) >= DateTime.Now
Datetime.ParseExact(x(“SD”).ToString, “dd-MM-yyyy”, Nothing) <=
DateTime.ParseExact(x(“ED”).ToString, “dd-MM-yyyy”, Nothing) > DateTime.Now ).ToList