What I want to do is simple. If the DateTimeOffSet
of a created Event is older than 24 hours I want it removed from the database. I am having a huge amount to trouble working with Converting System.Linq.IQueryable
to System.DateTime
.
Any help will be greatly appreciated. This is the Index of Events
public ActionResult Index()
{
IQueryable<DateTimeOffset> b = db.Events.Select(x => x.EventTime);
DateTimeOffset currentDate = DateTimeOffset.Now;
if (currentDate > b)
{
db.Events.Remove(@event);
db.SaveChanges();
return View(db.Events.ToList());
}
return View(db.Events.ToList());
}
My other question is how could I structure this so that it requires a 24 hour difference in order to remove the row from database.
The data table has the EventTime as a DateTimeOffset
data type.
I have also been trying to use
DateTimeOffset.Compare(currentDate, b);
But Visual Studio isn't liking that line as well. Please help if you know how to compare a time from a database to current time. There is really nothing like this in regards on this site. I Have spent all day on this site and have yet to find something along this.
Thanks