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.
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.
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()
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
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
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
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
we can modify the returned String of the date, when defining the Format String
Ensure the following:

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
You’re welcome @0bb4628e217fd43ac86ac9294
Happy Automation!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.