How to sort a Datatable by date?

Hello
I have a date in this format
Screenshot_5
I need to save only those dates that fall within the next 16 days from today’s date

Example
Screenshot_6

thanks for your help

I need to save only those dates that fall within the next 16 days from today’s date

Use this in filter datatable Convert.ToDateTime(“ColumnName”)<datetime.now.adddays(16).

You might want to take care of exceptional handling while using the Convert.ToDateTime

image
@Sriharisai_Vasi, error - column type is not supported

sry please remove convert.todatetime in column name

Hey @Aibek_Abubakirov

The Column Value should be present inside double quotes and don’t convert it.
from your input file i can see there is no Header value.
if you are using Read Range activity to get data from excel then Uncheck the AddHeaders option.

if you uncheck AddHeaders Uipath will automatically add column names like Column0, Column1.

in your case as it is first column then it will be Column0.

“Column0” < datetime.now.adddays(16).

let me know if you need any help on this.

Regards,
Vijay.


I used this sort, but finds nothing

I used this sort, but finds nothing

How to sort a Datatable by date?

@Aibek_Abubakirov
Find a demo xaml here for starter Help
Aibek_Abubakirov.xaml (6.5 KB)

1 Like

@Aibek_Abubakirov
Find a demo xaml here for starter Help
Aibek_Abubakirov.xaml (6.5 KB)

Well done. thanks a lot @ppr

But what about when such a date is not on the list?

It turns out an error when there is no date of 16 days

@Aibek_Abubakirov
IT was Just about fast prototyping. In Case of No rows will be returned the CopyToDataTable throws an exception. Use instead of CopyToDataTable a ToList Statement this will Return alist of datarows. Now you can check the Count and If rows are returned then you can execute the CopyToDataTable

1 Like

@ppr I didn’t understand, could you explain in a bit more detail?

@Aibek_Abubakirov

Aibek_Abubakirov_V2.xaml (7.4 KB)

1 Like

@ppr checked your XAML file(V2), but the result returned nothing

@Aibek_Abubakirov
please send your testdata Excel or Values, so I can check at my end

1 Like

@ppr This can be done in the Filter Data Table?

@Aibek_Abubakirov
As we are Close to completion and my Testdates are running without exceptions so checking IT with your Testdata will Bring Out fast a Resolution. Please Provide Testdata or Sample values, thanks

1 Like

@ppr
Error.txt (2.1 KB) Screenshot_3

Test.zip (35.0 KB)

@Aibek_Abubakirov
was just a trim / additional spaces issue. Now its running
grafik

Just change to

(From d In dtData
Let dt = DateTime.ParseExact(d(0).toString.trim,“dd.MM.yyyy”, CultureInfo.InvariantCulture)
Where dt >= Now And dt <= Now.AddDays(16)
Order By dt
Select d).toList

2 Likes

@ppr @Vijay_Kumar_C @Sriharisai_Vasi

Error - CultureInfo is not declared

I tried installing System.Globalization.CultureInfo packages, but they do not install