Dan
Dan

Reputation: 1480

asp.net MVC 3 DateTime linq

I have a table of events, I need a linq query that will return all events from a certain month and year, not day.

something like

var monthquery = from c in db.events
                  where c.startdate.month == DateTime(MonthValue, Year Value)
                  select c;

I just don't know the syntax. What do I put in instead of MonthValue to get July, for instance?

Thanks in advance

Upvotes: 0

Views: 567

Answers (1)

Jonathan
Jonathan

Reputation: 12025

Instead of MonthValue, you can put the integer that represents the month ...

var monthquery = from c in db.events
                  where c.startdate.month == IntegerThatRepresentTheMonth 
                  && C.startDate.Year == IntegerThatRepresentTheYear
                  select c;

Upvotes: 3

Related Questions