How to pick latest date in excel using UiPath

Hi Team,

I have one excel with different dates. I want to pick latest date from the excel using UiPath. Also get the index of the particular date.

Please suggest…

Thanks
Baby

the date format in the excel is same?

Hello @Baby123

Here can you sort the data table using the date column and then get the first-row value?

Thanks

Hi @Baby123 Welcome once again.
Please try like this…

(From r In DT Order By DateTime.ParseExact(r.Item(“YourColumnName”).ToString, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) Descending Select r).CopyToDataTable

It will sort your date and put date format according your format.
This Format “MM/dd/yyyy”, is for 12/4/2012

Hi @Baby123
Another method.
Give a try at

AssignActivity
myMaxDateTime =

(From d In YourDataTableVar.AsEnumerable
Where DateTime.TryParseExact(d("Column1").toString.Trim, "MM-dd-yy", CultureInfo.InvariantCulture, DateTimeStyles.None, Nothing)
Let  x = DateTime.ParseExact(d("Column1").toString.Trim, "MM-dd-yy", CultureInfo.InvariantCulture)
Select v = x).Max(Function (x) x)

Note ->It will not reorder your datatable.

Hi @Rahul_Unnikrishnan and @raja.arslankhan,
Thank you for your reference.

I tried both secenrios but I am facing the error .
Please find the attachment for your reference


I gave correct column name but it’s showing error .

Kindly suggest

@Baby123 can you give me excel file?
I think you have case sensitive issue with column. please try again.

inside the bracket you don’t need to use r.item, instead use as below

r(“UpdatedSort in Descending order”).ToString.Trim

“UpdatedSort in Descending order” is your column name. Also make sure in the datatable you have header row.

Thanks

Hi @raja.arslankhan ,

Please find the attachment below for your reference.
input.xlsx (8.4 KB)

Kindly suggest

@Baby123
image
your excel column containing something like this. please remove and check.
I am also checking.



Latestdate.xaml (6.6 KB)

check this one it will return latest.

(From d In DT1.AsEnumerable
Where DateTime.TryParseExact(d(“UpdatedSort in descending order”).toString.Trim, “yyyy-MM-dd HH:mm”, CultureInfo.InvariantCulture, DateTimeStyles.None, Nothing)
Let x = DateTime.ParseExact(d(“UpdatedSort in descending order”).toString.Trim, “yyyy-MM-dd HH:mm”, CultureInfo.InvariantCulture)
Select v = x).Max(Function (x) x)

Hi @Baby123

Check out the XAML file

SourtOutExcelDate.xaml (9.1 KB)

Regards
Gokul

Alternative Method

Instead of give the column name you can try with column index

DtRead.AsEnumerable().Max(Function (drRows) DateTime.Parse(drRows.Item(9).ToString)).ToString

Check out the XAML file

SourtOutExcelDate.xaml (8.8 KB)

Output

image

Regards
Gokul

@Baby123
please check I have uploaded solution with query and column issue

Thanks for your help and support.
Will check update you ASAP

@Baby123 Welcome, I am available.

Hi @raja.arslankhan ,
How to remove that Highlighted question mark using UiPath and after filtering the latest date I want to extract latest DMR number whitch in the column in 7 .
input.xlsx (8.4 KB)

I want to remove all the question mark in the columns and get the latest date and DMR number which in the column 9 and 7.

Thanks
Kindly suggest

Hi @Gokul001 ,
It’s working fine but I want give the column name not index
Kindly suggest how to remove the question mark and after that give the column name
Then will get the latest date and DMR number

Thanks

Hi @Baby123

You can try with pass the column like this

DtRead.AsEnumerable().Max(Function (drRows) DateTime.Parse(drRows.Item("UpdatedSort in descending order ").ToString)).ToString

image

Regards
gokul

Hi @Gokul001 ,

After fliter the date I want to extract latest DMR number which is in column,7 …
Please suggest

@Baby123
There is no need to remove, you can get columnName by giving this expression.
‘DataTable.Columns(Index).ColumnName’