How to Select Min and Max date values in Linq Query?

This should work for you Retrieve Minimum Date var MinDate = (from d in dataRows select d. Date).Min(); //Retrieve Maximum Date var MaxDate = (from d in dataRows select d. Date).Max() (From here ).

This should work for you //Retrieve Minimum Date var MinDate = (from d in dataRows select d. Date).Min(); //Retrieve Maximum Date var MaxDate = (from d in dataRows select d. Date).Max(); (From here).

– Erwin1 Mar 5 at 1:21 probably call d in second string as from D2 in datarows select D2. Date – Valentin Kuzub Mar 5 at 1:29 @Erwin1, it's because you have a different variable called d (which is a pretty bad for a local variable, may I say!). Rename that variable or use a different name for parameter, e.g. Row.

– Dan Abramov Mar 5 at 1:49 @gaearon - you'd hate my lambda expressions then, they are always x and y's, i. E, query. Where( x => x.Name == "Foo" ) – Metro Smurf Mar 5 at 1:56 Tried this and still getting an error Datez is not a member of Date; Dim mm = From DD In (From cv In T1s Select Datez = (cv.

Date1)) Select DD.Datez.Min() mm.dump() – Erwin1 Mar 5 at 2:13.

If you are looking for the oldest date (minimum value), you'd sort and then take the first item returned. Sorry for the C#: var min = myData. OrderBy( cv => cv.

Date1 ).First(); The above will return the entire object. If you just want the date returned: var min = myData. Min( cv => cv.

Date1 ); Regarding which direction to go, re: Linq to Sql vs Linq to Entities, there really isn't much choice these days. Linq to Sql is no longer being developed; Linq to Entities (Entity Framework) is the recommended path by Microsoft these days. From Microsoft Entity Framework 4 in Action (MEAP release) by Manning Press: What about the future of LINQ to SQL?

It's not a secret that LINQ to SQL is included in the Framework 4.0 for compatibility reasons. Microsoft has clearly stated that Entity Framework is the recommended technology for data access. In the future it will be strongly improved and tightly integrated with other technologies while LINQ to SQL will only be maintained and little evolved.

Metro Smurf That will not work because I want to test on multiple date columns in the same table. I will end up with too many sorts. – Erwin1 Mar 5 at 2:01 @Metro Smurf Thanks for the advise on EF4.Is there syntax difference is putting the Linq-to-SQL or Linq-to-Entities query?

– Erwin1 Mar 5 at 2:06 @Erwin1 - please update your question to reflect what you are trying to achieve, re: the question doesn't mention anything about multiple columns. Regarding EF4 vs Linq to Sql syntax differences, I really don't know as I've never used Linq to Sql; but, I'm gonna go out on a limb and say yes, there will be quite a bit of syntax differences. – Metro Smurf Mar 5 at 2:11 @Metro Smurf I have updated my question, I hope that you can help.

In VB I do not have access to Lambda's. – Erwin1 Mar 5 at 2:17 Are you returning multiple rows back from the database or just a single row? – Metro Smurf Mar 5 at 2:43.

Dim mydate = from cv in mydata. T1s select cv. Date1 asc datetime mindata = mydate0.

Thanks, but that would not work if I want to get min and max on table that has a number of date columns. I. E I want to do this on say 4 columns.

– Erwin1 Mar 5 at 1:10 select new { mindate = cv. Min( cv. Date1) }; – Praneeth Mar 5 at 1:26 sorry, but it says "min" is not a memeber of LINQPad.User.

T1s. (Iam testing the code on LinqPAD) – Erwin1 Mar 5 at 1:42.

I am moving from SQL to Linq and I need some help. I am testing both Linq-to-SQL and Linq-to-Entities. I want to try both to decide which one suits me best.

Your help is appreciated. What is the correct syntax (in vb.net if possible) to select the minimum date value from a table? Is giving this error 'Min' is not a member of 'Date'.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions