Hi All,
I am trying to extract the max date from a Data Table. I have rows of Invoices with multiple dates and I need to select the max date. I am trying to scrape the data and put in data table. from there I am using Linq to get the maximum dates. However I am getting error in Linq .
Convert.ToDateTime( ((From DataRow CurrentRow In ExtractDataTable_Invoice.Rows Orderby Convert.ToDateTime(CurrentRow[“Date”]) Descending Select CurrentRow).FirstOrDefault()[“Date]”))
I need to pick the latest date . 7/31/2022 and these dates can vary in run time however I need to pick up the latest dates
Hey everybody,
I want get min and max of my date column “[RÇU]Date de réception (Date)” of my datatable ‘dt’.
Can you help me ?
Thank !
change format accordingly
adiijaiin
(Aditya Jain)
June 7, 2023, 6:13am
3
Hi @dutta.marina
Sometimes the Convert.ToDateTime doesn’t Work correctly.
Can you try with the following expression, that might help you.
Datetime.ParseExact(“give your date here”,“M/dd/yyyy”,Gloabalization.CultureInfo.InvariantCulture)
Yoichi
(Yoichi)
June 7, 2023, 6:14am
4
Hi,
If you use C#, can you try the following?
Convert.ToDateTime( ((from DataRow CurrentRow in ExtractDataTable_Invoice.Rows orderby Convert.ToDateTime(CurrentRow["Date"]) descending select CurrentRow).FirstOrDefault()["Date"]))
Regards,
Hi Yoichi,
I am getting following error.
Hi @adiijaiin
I have used DateTime.TryParseExact( ((from DataRow CurrentRow in ExtractDataTable_Invoice.Rows orderby DateTime.TryParseExact(CurrentRow[“Date”]) descending select CurrentRow).FirstOrDefault()[“Date”])) but still getting error.
adiijaiin
(Aditya Jain)
June 7, 2023, 6:31am
9
while using ParseExact you need to give the input format of the date as well.
Yoichi
(Yoichi)
June 7, 2023, 6:31am
10
Hi,
Can you share your workflow file if possible?
Basically it’s necessary cultureinfo and result argument if you use TryParseExact method.
Regards,
Hi Yoichi
Please find the file.Thank You
Date_Time.zip (3.3 KB)
Hi @adiijaiin
Is it something which I can write ? Let me know if this is correct. Attached my workflow also.
Date_Time.zip (3.3 KB)
ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r([“Date”]).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r([“Date”]).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString(“MM-dd-yyyy”)
Yoichi
(Yoichi)
June 7, 2023, 7:59am
13
Hi,
We cannot open this project correctly. Can you check if can open this?
Regards,
Anil_G
(Anil Gorthi)
June 7, 2023, 9:24am
14
@dutta.marina
Can you please confirm if yours is a c# or vb.net project…
Because i see a combination you are using in the code
Cheers
Hi @Yoichi
I have uploaded again. Can you check now.
Main.xaml (10.6 KB)
Anil_G
(Anil Gorthi)
June 7, 2023, 9:54am
17
@dutta.marina
Then can you please try this please
Cdate(ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r(("Date")).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r("Date").ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None))("Date").ToString).ToString("MM-dd-yyyy")
Cheers
@Anil_G
I tried but getting error.
Anil_G
(Anil Gorthi)
June 7, 2023, 10:03am
19
@dutta.marina
A small correction to the above
ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r(("Date")).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r("Date").ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString("MM-dd-yyyy")
Cheers
@Anil_G
Thank You very much. Error has gone. But can you please explain the code ?Also why we are using the Function(r)?
Thanks once again