Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3796396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:13:48+00:00 2026-05-19T13:13:48+00:00

In the LINQ statement below, I want to select people with an exam date

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:13:49+00:00Added an answer on May 19, 2026 at 1:13 pm

    You can just use the Year property on DateTime:

    var active = from p in dc.People
                 where p.Exam.Year >= 2010
                 select new {
                     p.ContactID,
                     p.FirstName,
                     p.LastName
                 };
    

    Why is .Value necessary to access .Year? Exam is a nullable datetime.

    Exactly because Exam is a Nullable<DateTime>. When you declare an instance of Nullable<DateTime> like

    DateTime? exam;
    

    note that exam is not a DateTime and therefore you can’t directly access the properties of DateTime. To get a concrete instance of DateTime you use the Value property on Nullable<DateTime> (all Nullable<T>s have this property) so that

    DateTime instance = exam.Value;
    

    is a DateTime assuming that exam is not null. You can therefore say

    int year = instance.Year;
    

    and, of course, for brevity

    int year = exam.Value.Year;
    

    Note that this will throw if exam.HasValue is false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert a sql statement to a linq query. The code below
I have following LINQ statement and I want to rewrite it using extension methods.
I need some help converting the SQL found below to an equivalent LINQ statement
Is there a way to write the ToDictionary statement below using the SQL-ish Linq
I am trying to mimic below statement in Linq to SQL. WHERE (rtrim(posid) like
I have a LINQ Statement. It searches an XML file. (See example below) There
I'm have been trying to convert the foreach statement below to a LINQ statement
I keep getting this error with my below LINQ statement, and I can't figure
I'm trying to execute the code below (in LINQPad), and my LINQ statement is
If I created a Linq statement as shown below, it works fine. var Jobs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.