Jocelyn
Jocelyn

Reputation: 153

How to filter LINQ with date

my code:

var query = from s in ctx.location
        join b in ctx.order on s.locationID
        equals b.ID
        join e in ctx.offerdata on b.OrderID
        equals e.OrderID

        where(e.delDate.ToString().Contains("2013"))

       orderby e.identity_no
       select new Order
       {
    ...

       };

      return query.ToList();

But this ist not working ... so how must my LINQ look like, that ich can only see Orders of 2013 ...

Thanks a lot!

Upvotes: 1

Views: 80

Answers (3)

Jon Skeet
Jon Skeet

Reputation: 1504182

Well you're really interested in the year, right? So try:

where e.delDate.Year == 2013

EDIT: As we now know that delDate is a DateTime? it would be:

where e.delDate != null && e.delDate.Value.Year == 2013

Upvotes: 3

Tim Schmelter
Tim Schmelter

Reputation: 460380

If it's a DateTime why do you convert it to string?

var query = from s in ctx.location
        join b in ctx.order on s.locationID
        equals b.ID
        join e in ctx.offerdata on b.OrderID
        equals e.OrderID

        where(e.delDate.Year == 2013)

Upvotes: 2

Moho
Moho

Reputation: 16573

Use:

e.delDate.Year == 2013

...

Upvotes: 2

Related Questions