Recent Date

Hi all,
In an Excel sheet I have a column by name TrDate in that column I have dates in string format. I need to find the recent date among the other dates.

Can you help to how to find recent date.

Thanks in advance.

@0bb4628e217fd43ac86ac9294

Assign activity: recentDate = (From row In YourDataTableVar.AsEnumerable()
                               Let dateValue = DateTime.ParseExact(row("TrDate").ToString(), "your_date_format_here", CultureInfo.InvariantCulture)
                               Order By dateValue Descending
                               Select dateValue).FirstOrDefault()

Hi @0bb4628e217fd43ac86ac9294

Try the below syntax:

mostRecentDate = (From row In yourDataTableVariable.AsEnumerable()
                  Let currentDate = DateTime.ParseExact(row("TrDate").ToString(), "your_date_format_here", CultureInfo.InvariantCulture)
                  Order By currentDate Descending
                  Select currentDate).First()

mostRecentDate is of DataType System.DateTime.

Please specify the Date format so that I can help you with redefind query.

Regards

HI @vrdabberu Thank you for your help, I am getting the output as 09-02-2024 00:00:00 I dont want the time I want only the date. How do I do that

Hi @0bb4628e217fd43ac86ac9294

Try this syntax:

mostRecentDate = (From row In yourDataTableVariable.AsEnumerable()
                  Let currentDate = DateTime.ParseExact(row("TrDate").ToString(), "your_date_format_here", CultureInfo.InvariantCulture)
                  Order By currentDate Descending
                  Select currentDate).First().ToString("dd-MM-yyyy")

mostRecentDate is of Datatype System.String

Regards

@0bb4628e217fd43ac86ac9294

Assign activity: recentDate = (From row In YourDataTableVar.AsEnumerable()
                               Let dateValue = DateTime.ParseExact(row("TrDate").ToString(), "your_date_format_here", CultureInfo.InvariantCulture).Date
                               Order By dateValue Descending
                               Select dateValue).FirstOrDefault()

Then please try this approach hope it helps

The Date in Excel is in dd-MM-yyyy format but in recentDate is coming as MM/dd/yyyy HH:mm:ss
what can I do for this

Hi @0bb4628e217fd43ac86ac9294

Try this:

This will print the date in the format dd-MM-yyyy

Regards

@0bb4628e217fd43ac86ac9294

After giving this query you are getting MM/dd/yyyy HH:mm:ss

Assign activity: recentDate = (From row In YourDataTableVar.AsEnumerable()
                               Let dateValue = DateTime.ParseExact(row("TrDate").ToString(), "your_date_format_here", CultureInfo.InvariantCulture).Date
                               Order By dateValue Descending
                               Select dateValue).FirstOrDefault()

This is the updated one so please try this if it does not work for you please ask

@rlgandu yes after giving that query in assign I am getting in MM/dd/yyyy HH:mm:ss

Hi @0bb4628e217fd43ac86ac9294

Try this. This will print the date in the format dd-MM-yyyy

Regards

we can modify the returned String of the date, when defining the Format String
Ensure the following:
grafik

Assign Activity
strDateMax | DataType: String

YourDataTableVar.AsEnumerable().Select(Function (x) DateTime.ParseExact(x(ColNameOrIndex).toString.Trim,YourParseFormat,CultureInfo.InvariantCulture )).Max(Function (x) x).toString(YourOutPutFormat)

Thank you @vrdabberu this is working for me

1 Like

You’re welcome @0bb4628e217fd43ac86ac9294

Happy Automation!!

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