Conversion from string to "" type 'Date' is not valid

I am using following linq query. and following is my flow. I am getting Conversion error. I tried multiple things from the forum, but could not resolve the query, I need Max Date and Time from the sheet.
linq query is written in Send Email Sequence.

(From row In dtInput
Group By id=row(0) Into grp = Group
Login Process.7z (164.2 KB)
Let md=grp.Max(Function (d) d(1))
Select dtMax.Rows.Add({id,CDate(md.Tostring).ToString(“MM/dd/yyyyy”)})).CopyToDataTable

Please help

Login Process.7z (164.2 KB)


Its because of empty strings…you can try as below

(From row In dtInput Group By id=row(0) Into grp = Group Let md=grp.Max(Function (d) d(1)) Select dtMax.Rows.Add({id,If(md.ToString.Trim.Equals(String.Empty),"",CDate(md.Tostring).ToString("MM/dd/yyyyy"))})).CopyToDataTable

Have added if condition to check if there are any blanks


I tried it but now it is giving : Object reference not set to an instance of an object


This comes when there is a null
Value…can you check something is missing…can you try checking the datatable values as well

Is dtMax initialized? If not intialize it with new datatable…

Better us a build datatable and create two columns as you need…make sure to have the correct column type


It was my bad. I got the solution from your query. Thank you very much

1 Like


Happy Automation…

Please mark solution and close so that other with similar query can get help


Just got curious,

If I want to find the max time if all dates are same then what change i will need here?

i.e. Login Date Login Time
3/4/23 12:15 PM
3/4/23 12:30 PM
3/4/23 12:45 PM
3/4/23 1:30 PM

From this I have same dates then it should go with latest time? How will it work

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