How to compare dates in LINQ query using C# .Net

Last Reply on Aug 20, 2014 03:58 AM By Azim

Posted on Aug 20, 2014 03:57 AM

i want to compare date using greater than equal to operator instead of== operator.

My code is as:

public ActionResult ShowSelect(trnapply obj)
{
var query = from s in db.trnapplies where (s.txtEmpFromDate == obj.txtEmpFromDate) select s;

ViewBag.data = query; 

return View();


}

 

Posted on Aug 20, 2014 03:58 AM Modified on on Aug 20, 2014 03:58 AM

You need to convert to DateTime.

public ActionResult ShowSelect(trnapply obj)
{
    var query = from s in db.trnapplies where (Convert.ToDateTime(s.txtEmpFromDate) >= Convert.ToDateTime(obj.txtEmpFromDate)) select s;
    ViewBag.data = query;
    return View();
}

I have not tested it.