Skip to content

Instantly share code, notes, and snippets.

@ChadRoberts21
Created April 19, 2018 10:57
Show Gist options
  • Save ChadRoberts21/c7994ada0b3359191958a5375741c59f to your computer and use it in GitHub Desktop.
Save ChadRoberts21/c7994ada0b3359191958a5375741c59f to your computer and use it in GitHub Desktop.
Get Last 24h of data (LINQ)
// query= a Query object containing a search string
DateTime searchTime;
if (DateTime.TryParse(query.Search, out searchTime))
{
DateTime endTime = searchTime + new TimeSpan(24, 0, 0);
IQueryable linq = dbContext.DataTable
.Where(x => x.TimeStamp >= searchTime)
.Where(x => x.TimeStamp <= endTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment