How to compare only date components from DateTime in EF?

后端 未结 14 1026
野性不改
野性不改 2020-11-27 17:06

I am having two date values, one already stored in the database and the other selected by the user using DatePicker. The use case is to search for a particular date from the

14条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 17:30

    NOTE: at the time of writing this answer, the EF-relation was unclear (that was edited into the question after this was written). For correct approach with EF, check Mandeeps answer.


    You can use the DateTime.Date property to perform a date-only comparison.

    DateTime a = GetFirstDate();
    DateTime b = GetSecondDate();
    
    if (a.Date.Equals(b.Date))
    {
        // the dates are equal
    }
    

提交回复
热议问题