How to get Latest datetime from data table

Hi
I want to read latest date from datatable column
i am ussing this expressing but its not working

Please help me on this

Thanks
Vivek

Hi
Hope the below expression would help you resolve this issue

str_date = (From row In Dt Order By DateTime.ParseExact(row.Item(“yourcolumnname”).ToString, “dd/MM/yyyy”,
System.Globalization.CultureInfo.InvariantCulture) Descending Select row).First()(“modifiedon”).ToString

Cheers @Vivek_Kumar4

Hi,

Can you try the following expression?

Convert.ToDateTime( ((from dr in Dt1.AsEnumerable() orderby Convert.ToDateTime(dr["modifiedon"]) descending select dr)).First()["modifiedon"] )

Regards,

@Palaniyappan

Thanks for reply
I am ussing this but getting error
Could you please guide me in step by step

Hi @Vivek_Kumar4 ,

@Palaniyappan 's expression seems to be mixed VB and C#.

Do you use C#? Can you try the expression in my post (the following) ?

Convert.ToDateTime( ((from dr in Dt1.AsEnumerable() orderby Convert.ToDateTime(dr["modifiedon"]) descending select dr)).First()["modifiedon"] )

Doesn’t this also work?

Regards,

Hi


Same error

Hi,

In my environment, there is no error. Can you check the following sample(zip file)?

img20211025-6

Sample20211025-2.zip (2.2 KB)

Or do you use VB mode?

Regards,

Hi,

If you use VB mode, can you try the following?

Convert.ToDateTime( ((From dr In Dt1.AsEnumerable() Order By  Convert.ToDateTime(dr("modifiedon")) Descending Select dr)).First()("modifiedon") )

Regards,

Hi @Yoichi
I am using VB mode studio

@Yoichi
I am not able to open your code
getting error it will open in studio pro

image

Hi,

Thank you for reply.
The above sample (zip file) is C# project and it requires 2021.10 Studio or 21.4/20.10 Studio Pro.
At first, I thought you use C# because the expression dr["columnName"] is C# style indexer for getting item from Row. Please ignore the above sample file.

In vb mode, the following will work.

Convert.ToDateTime( ((From dr In Dt1.AsEnumerable() Order By  Convert.ToDateTime(dr("modifiedon")) Descending Select dr)).First()("modifiedon") )

Regards,

@Vivek_Kumar4
give a try on

Assign activity
LHS: myMinDate | DateTime
RHS:

DT1.AsEnumerable.Min(Function (x) Convert.ToDateTime(x("modifiedon").toString.Trim))

in case of other formats are present within the datatable we just adopt the dateTime conversion function

grafik