views:

303

answers:

1

How to add date is where clause. I am using following code.

    var opportunites = from opp in this.DataContext.Opportunities
                            join org in this.DataContext.Organizations on opp.OrganizationID
                            equals org.OrgnizationID
                            select new
                            {
                                org.CreatedDate,
                                org.OrganizationName
                            };
     if (createdDate != string.Empty)
         opportunites = opportunites.Where(opp => 
                            opp.CreatedDate == Convert.ToDateTime(createdDate));

But with this code i am not returning any result. I think the error is with == operator.

I think i should have code like this

"where createdDate between" + createdDate + "00:00:00" + and createdDate + "23:59:59"

How to archive this thing in LINQ.

Any suggestion??

+5  A: 

You can extract just the 'date' portion of a DateTime as follows:

opp.CreatedDate.Date == Convert.ToDateTime(createdDate).Date
Bruce