How to get the older dates than the current month

Mariana,

The solution will work to get all records older than current date. However in your excel file all the records having older dates hence you are getting all records in output.

Add some records of today’s date & future dates and verify.

Also if you want to filter it out for any other date rather than current date please substitute your required date value or variable in place of Now.ToString("dd-MM-yyyy)

No t the current Date, It should be Current Month. I have tested it But it getting all the records @rohith.prabhu

DateFilter.zip (77.3 KB)
Hello @Marian_B , Please refer this Flow, You may got some idea.

Regaerds,
Gokul

To get date older than current month use the below
Input_DT.Select(“[Date]<'”+Now.ToString(“MM-yyyy”)+“'”).CopyToDataTable

(As your data is formatted to Date format in excel file, it will work for your excel file)

It is getting all the records @rohith.prabhu

Hi @Marian_B ,

Could you Check the below Expression :

Input_DT.AsEnumerable.Where(Function(x)CDate(x("Date").ToString).Month<Now.Month).ToArray

Also you would need to follow the below Post to handle the Errors when you convert directly the Filtered Datarows into Datatable.

There might be additional conditions that need to be added if there are multiple date formats/Empty values or change the CDate() to DateTime.ParseExact() to get the appropriate results.

Let us know if the expression doesn’t work, we can change the expression according to the results or the Error Message you receive.

1 Like

@Marian_B ,

Maybe the requirement is different than what it seems, From the Output we can see that the date 11/07/2022 is not present. We would require to know what is the logic you have used
image

@supermanPunch

Here is the workflow

OlderDate.xaml (7.5 KB)

Input -
Sample.xlsx (5.3 MB)

I need to Get the Older Dates than the current month in the Date column

Filter expression is not working

@Marian_B ,

It seems that you have eliminated all the dates of the Previous Month as well as per the Output. So is the Logic actually to keep only the Dates lesser than (Current Month - 1) meaning dates lesser than July ?

Then maybe check the below modified Workflow if it reflects what you actually require. Let us know if this is not the required approach.
OlderDate.xaml (8.1 KB)

Hey @Marian_B

You will need to get all the older dates which is not in Current Month - Is that correct ?

Thanks
#nK

Requirement is Eliminate all the date which are older @supermanPunch.

Need to keep Current Month and greater Month only

Current month or Greater Month @Nithinkrishna

1 Like

@Marian_B , The Sample Output you have provided doesn’t meet this requirement.
image

Needed only the Eliminate Month @supermanPunch , So the Output looks like Only eliminated Month

Apologies for the wrong input file Here is the correct one @supermanPunch

Sample.xlsx (5.3 MB)

1 Like

@Marian_B ,

Have you Checked if the above workflow that I have provided, gives you the required output for this input file ?

Let us know if it doesn’t provide the same Output.

Expression is working in the Date column in have empty row. Bot throws an error @supermanPunch

image

Tried with this expression

DtreadFull.AsEnumerable.Where(Function(x)(CDate(x("Date").ToString).Year <= Now.Year) OrElse (CDate(x("Date").ToString).Month<(Now.Month)) OrElse isNothing(x("Date")) OrElse String.IsNullOrWhiteSpace(x("Date").ToString)).ToArray.copytodatatable

@Marian_B , What should be the output when there are empty values in date column, Do you want to Include it in the Output or remove it ?

Also, What is the Condition with inc.per.CF column ?

Need to remove it from the output. @supermanPunch

I have update the expression. By mistake i have placed it wrongly. Just ignore it

@Marian_B ,

In that case, Could you Check the below modified expression :

DtreadFull.AsEnumerable.Where(Function(x)Not(String.IsNullOrWhiteSpace(x("Date").ToString)) AndAlso ((CDate(x("Date").ToString).Year <= Now.Year) AndAlso (CDate(x("Date").ToString).Month<(Now.Month)))).ToArray.copytodatatable

We would require to first Check whether date is empty or not and then convert the date value using CDate().

Let us know if you get any other errors.

Its working all the older Month and Current, But its not working for 2021 @supermanPunch