DateTime.Today in mvc

Total Post:88

 1409  View(s)
Rate this:

I am trying to return a view which will display the logs from current day.

This sql query does exactly what i need.

select * from Logs where Date>=GETDATE()-1

but I am having trouble with the razor syntax to write this statement in my view.

return View(db.Logs.Where(a => a.Date >= DateTime.Today() - 1));

Any idea how to display logs in the view for the current date?

  1. Post:194

    Re: DateTime.Today in mvc

    try this:

    return View(db.Logs.Where(a => a.Date == DateTime.Today));

      Modified On Apr-05-2018 11:14:08 PM