score:3
Accepted answer
When working with DateTime.Now
, you should always store it in a local variable otherwise you can get really nasty bugs from the clock changing between calls:
var now = DateTime.Now;
var query = from v in dc.VisitorInfors
where v.VisitTime.Date == now.Date
select v;
score:0
Use DateTime.Now
:
DateTime currentDate = DateTime.Now;
var query =
from v in dc. VisitorInfors
where v.VisitTime == currentDate.Date
select v;
Source: stackoverflow.com
Related Articles
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Use a linq query as microsoft local report Data Source (WinForms)
- Using LINQ query result for data source for GridControl c#
- linq how to query a specific date's data
- Linq query to remove all data containing a specific matching number
- Linq to query data between 2 dates when within a group
- LINQ query to select specific data
- Linq query null check in data source
- c# Linq or code to extract groups from a single list of source data
- Linq query to Get Data between two Dates
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- Linq query to get data from a specific RavenDB collection not working as expected
- LINQ query code for complex merging of data
- How do I drill down to specific data in my LINQ query result?
- LINQ query — Data aggregation (group adjacent)
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Query data using "Contains" keyword in Dynamic Linq in C#
- LINQ to SQL: Complicated query with aggregate data for a report from multiple tables for an ordering system
- Filling in missing dates using a linq group by date query
- Filter data between two dates using LINQ
- LINQ - using a query expression to calculate data time difference
- LinQ query with multiple tables and extracting data
- LINQ Query to insert data into the database
- How does linq actually execute the code to retrieve data from the data source?
- LINQ Source Code Available
- LINQ EF Join query from 2 different data context
- What is the return type for a anonymous linq query select? What is the best way to send this data back?
- LINQ query performance issue when fetching data from db in MVC Razor
- Date range falling between two dates in a LINQ query
- how do I write LINQ query to retrieve distinct records based on only specific properties?
- Check if a CSV string contains a given value C#
- How to do a twitter search using linq to twitter v.4 in c#
- Create GroupBy Statments Dynamically By Strings Array - Linq to Entity
- Can I using LINQ return a List<Person> from a List<String>
- C# XML LINQ Query to LIST<>
- Removing Duplicates from LINQ results
- Compare only Date in nHibernate Linq on a DateTime value
- Recent users query
- Inline IF with no ELSE
- How do I decipher the Select method docs on MSDN?
- Question considering LINQ to Excel
- flat list object into view
- Methode Call twice inside LINQ Query
- Why a .Union() changes the order of the items?
- Do you know another way to do this "massive" linq filtering?
- Better Linq parsing of Large XML data
- How to filter a collection of a collection in linq?
- Dynamically build predicates using linq-to-xml on windows phone
- Building a dynamic where clause for dynamic keywords or using IQueryable C# Linq
- Converting SQL query to linq equivalent