How to use DateTime in WHERE clause (LINQ)?
c#, linq, linq-to-sql
Solution
You can extract just the 'date' portion of a DateTime as follows:
opp.CreatedDate.Date == Convert.ToDateTime(createdDate).Date
Problem
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??