user673906
user673906

Reputation: 857

LINQ querying for multiple dates and counting rows

Hi I want to know how to do two things with LINQ This question is probably more a SQL/C# thing I firstly want to query with multiple dates How would I do this?

For example I want to query every date in 2011 in a DateTime SQL Column So I want to find 01/01/2011 to 31/12/2011 I guess I would replace the first day month numbers with something e.g ##/##/2011

Secondly how do I count rows would it be like this "var rowCount = qRows.Count();"

Thanks

Upvotes: 0

Views: 606

Answers (4)

curtisk
curtisk

Reputation: 20175

Slightly different take on earlier answer(if you were pulling the date from another object for instance):

              DateTime myDate = new DateTime(2011,1,1);
                var results = (from t in dc.events
                               where t.event_date.Value.Year.Equals(myDate.Year)
                               select t).ToList();
                int testCount = results.Count();

Upvotes: 0

Hogan
Hogan

Reputation: 70528

from x in somethingwithdate
  where x.adate > '1/1/2000'
  where x.adate < '1/1/2010'
   select x

you can also do x.Count

Upvotes: 1

DooDoo
DooDoo

Reputation: 13487

try this :

List<Order> ord = (from o in dc.Orders
                               where o.OrderDate.Value.Year == 2011
                               select o).ToList();

            int Count = ord.Count;

Upvotes: 3

skaz
skaz

Reputation: 22650

You can do myDate.AddDays(1) repeated as many times as necessary.

Yes, you can do a Count() on the returned LINQ dataset.

Upvotes: 0

Related Questions