Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan in lambda expressions

Tags:

c#

lambda

I want to get lambda function that will query for items which were submitted in the last minute. How to specify this?

var items= Items.Where(i=>DateTime.Now.Subtract(i.Date)...)
like image 298
zsharp Avatar asked Nov 30 '22 19:11

zsharp


1 Answers

Take your pick

var items= Items.Where(i => DateTime.Now.Subtract(i.Date).TotalMinutes < 1)

or

var items= Items.Where(i => DateTime.Now.Subtract(i.Date).TotalSeconds <= 60)
like image 105
Daniel A. White Avatar answered Dec 15 '22 12:12

Daniel A. White