hi,
i have a datatable like this in some cases… in some cases there is no datatable …
if i found the datatable … i need to pick the latest date in the column-2 that is date and time…
and i want to pick the column-2 text… how can i do this
is there any approach
rlgandu
(Rlgandu)
July 31, 2023, 10:54am
2
@Nikhil_Katta
dt.AsEnumerable().OrderByDescending(Function(row) row.Field(Of DateTime)(“Column-2”)).First()
what is the datatype i have to put
ppr
(Peter)
July 31, 2023, 10:57am
4
in general we would try:
datascraping to the webtable and extract all data
using a LINQ, DataTable.Compute… for getting the latetest date
It looks that the datestring contains an @
. Here we have to decide which string to dateTime parsing approach will be the preferred one e.g. DateTime.ParseExact
this like iam getting when i scrape the datatable using datascrapping
if i use datarow as a datatype im getting this error
ppr
(Peter)
July 31, 2023, 11:04am
8
dateLatest | String =
YourDataTable.AsEnumerable.OrderBy(Function (x) DateTime.ParseExact(x("Column-2").toString.Trim,"MM/dd/yyyy @ h:mmtt",System.Globalization.CultureInfo.InvariantCulture)).Last()
vrdabberu
(Varunraj)
July 31, 2023, 11:05am
9
@Nikhil_Katta
Use the “Read Range” activity to read your data into a DataTable variable. Let’s call it “dtData.”
Find the Latest Date
Add a “For Each Row” activity to loop through each row in the DataTable.
Inside the loop, use an If activity to compare the date in the current row with the latest date found so far.
You can use the DateTime.ParseExact method to convert the date from string format to a DateTime object for proper comparison.
DateTime.ParseExact(row("DateColumn").ToString(), "your_date_format_here", CultureInfo.InvariantCulture) > latestDate
If the date in the current row is greater than the latest date found so far, update the “latestDate” variable with the value from the current row.
Output the Latest Date
After the loop, the “latestDate” variable will hold the latest date from the DataTable.
Hope it helps!!
ppr
(Peter)
July 31, 2023, 11:09am
11
Nikhil_Katta:
getting this error
corrected the code above due the @
was ommited
rlgandu
(Rlgandu)
July 31, 2023, 11:11am
12
@Nikhil_Katta
dt.AsEnumerable().OrderByDescending(Function(row) DateTime.ParseExact(row.Field(Of String)(“Column-2”), “your_date_format_here”, CultureInfo.InvariantCulture)).First()
Try using this
Parvathy
(PS Parvathy)
July 31, 2023, 11:33am
13
Hi @Nikhil_Katta
Use this in Assign activity:
latestDateRow= dtData.AsEnumerable().OrderByDescending(Function(row) DateTime.ParseExact(row("Column-2").ToString, "MM/dd/yyyy HH:mm tt", System.Globalization.CultureInfo.InvariantCulture)).First
latestDataRow Datatype: System.Data.DataRow
Use an If condition and give below condition:
latestDateRow isnot Nothing
Then
latestDate=DateTime.Parse(latestDateRow("Column-2").ToString())
Datatype of latestDate: System.DateTime
3. Print latestDate in Message Box
Please find the below workflow file:
Sequence26.xaml (9.8 KB)
Hope it works!!
latestDateRow isnot Nothing
Then
latestDate=DateTime.Parse(latestDateRow(“Column-2”).ToString())
not working
Parvathy
(PS Parvathy)
July 31, 2023, 11:46am
15
Can you show the error @Nikhil_Katta
Regards,
Parvathy
(PS Parvathy)
July 31, 2023, 12:00pm
17
@Nikhil_Katta
@Nikhil_Katta
Try this syntax in assign activity under If condition:
latestDateRow isnot Nothing
Then
latestDate=DateTime.ParseExact(latestDateRow("Column-2").ToString,"MM/dd/yyyy @ HH:mm tt",System.Globalization.CultureInfo.InvariantCulture)
latestDate Datatype: System.DateTime
Updated xaml has been uploaded
Sequence26.xaml (9.9 KB)
Regards,
can u plz check… i just atatched the doc
Parvathy
(PS Parvathy)
July 31, 2023, 12:04pm
20
@Nikhil_Katta
I have uploaded the updated xaml with your excel sheet.
Sequence26.xaml (9.9 KB)
Output:
Regards,
This is my datatable after extracting… you can see here my latest date is 01/01/2022 @ 1:23AM
But why we are getting the datewrong