Data column into Date type and sort from newest to oldest

Hi,
I’m using this code in assign:

I get an error:
image

Can anyone please advise?
Thank you

@hp321

in place of “MM/dd/yyyy”

use this

{"MM/dd/yyyy hh:mm:ss","MM/dd/yyyy","dd/MM/yyyy"}

thanks @Shiva_Nikhil ,
Now I don’t get an error,but the first date I get is 2019…there are more recent dates…
Please advise

@hp321

can you try this

(From r In dt.AsEnumerable
Order By datetime.ParseExact(r("ColumnName").ToString.Trim,{"MM/dd/yyyy hh:mm:ss","MM/dd/yyyy HH:mm:ss","dd/MM/yyyy"},system.Globalization.CultureInfo.InvariantCulture).Date 
Descending 
Select r).CopyToDataTable

Hello!

Can you try this? please.

dt.AsEnumerable.OrderByDescending(Function(r) DateTime.ParseExact(r(“ColumnName”).ToString().Trim,
{“MM/dd/yyyy hh:mm:ss”, “MM/dd/yyyy HH:mm:ss”, “dd/MM/yyyy”},
CultureInfo.InvariantCulture).Date).CopyToDataTable

Thanks @Shiva_Nikhil !
I just changed the last time expression to display the month first

Thanks Mariemily Silva for your help :slight_smile:

Thanks @ppr for your help

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.