Get highest date and is id number

My input data table is
ID. Date

  1. 12/31/2020
    
  2.  12/31/2021
    
  3.   12/31/2023
    
  4.    12/31/2022
    

Here the highest date is 12/31/2023

I should get the output as 12/31/2023 and its corresponding folder id

1 Like

@sruthesanju

use sort datatable on date column and then first row will contain the info you need

cheers

1 Like

Hi @sruthesanju

Build Data Table
image
Output->inputDataTable
=> Use below syntax in Assign:

Output = (From row In inputDataTable.AsEnumerable()
                    Let dateValue = DateTime.ParseExact(row("Date").ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")
                    Order By dateValue Descending
                    Select New With {
                        .Date = dateValue,
                        .ID = Convert.ToInt32(row("ID"))
                    }).FirstOrDefault()

Output is of DataType System.Object.

Regards

1 Like

Hey @sruthesanju
try this:
MyRow (datarow) = (From row In YourDataTable.AsEnumerable() Order By DateTime.ParseExact(row("Date").ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) Descending Select row).First()

to get values:

  • assign datetime variable:
    DateTime.ParseExact(MyRow("Date").ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
  • assign int32 variable:
    Convert.ToInt32(latestRow("ID")
1 Like