c# - Comparing a DateTimeOffSet From DataBase to Current Value -
what want simple. if datetimeoffset
of created event older 24 hours want removed database. having huge amount trouble working converting system.linq.iqueryable
system.datetime
.
any appreciated. 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 how structure requires 24 hour difference in order remove row database.
the data table has eventtime datetimeoffset
data type.
i have been trying use
datetimeoffset.compare(currentdate, b);
but visual studio isn't liking line well. please if know how compare time database current time. there nothing in regards on site. have spent day on site , have yet find along this.
thanks
it might easier comparison in query:
public actionresult index() { datetimeoffset currentdate = datetimeoffset.now.adddays(-1); iqueryable<event> events = db.events.where(x => currentdate > x.eventtime); foreach(var e in events){ { db.events.remove(e); } db.savechanges() return view(db.events.tolist()); }
you can loop through , remove each one. save changes outside loop committing changes once , not several times.
Comments
Post a Comment