tags:

views:

43

answers:

1

Hi, How can I write the linq query to check DateOfBirth is between given date.

A: 
 var IsBetween = (from p in People
                   where p.DateOfBirth.HasValue 
                       && lowDate <= p.DateOfBirth.Value 
                       && p.DateOfBirth.Value <= highDate
                   select true).FirstOrDefault();

-or -

 var IsBetween = 
        People.Where(p => p.DateOfBirth.HasValue)
              .Select(p => p.DateOfBirth.Value)
              .Any(date => lowDate <= date && date <= highDate);

Do you want the search limited to just one person?

James Curran