KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In the LINQ statement below, I want to select people with an exam date in 2010. The exam date is stored as a datetime as the actual date and time is used in other applications. What is the most elegant, easiest, best way to compare the exzam date to only '2010'. Or, should I just compare, using >=, the exam date to 1/1/2010? var active = dc.People.Where(x => x.exam >= 2010) .Select(x => new {x.ContactID, x.FirstName, x.LastName}) ); x.MostRecent == DateTime.Parse("1/1/2010").Year EDIT #1 I thought I should see a .Year on the exam date but I didn't. After seeing a couple of posts here I went back and found this works... .Where(x => x.exam.Value.Year == 2010) Why is .Value necessary to access .Year? Exam is a nullable datetime.
Tags (comma-separated)
Save Edits
Cancel