简体   繁体   中英

asp.net core 2.1 ef core 2.1 date compare not working on server

Hi there I am facing a very strange issue in asp.net core 2.1 I have a query selecting some data for a specific date like

var balances = dbContext.Balances.Where(x => x.BalanceDate.Date == workDay.Date); 

But the query is working on local ENV and even when i connect to remote SQL server. but on Server side it doesn't return any results.

It may have something to do with timezone or milliseconds included in the DateTime type in SQL Server. It can be one of the reasons above, You can do this ( == comparison only)

 var balances = dbContext.Balances.Where(x => 
     x.BalanceDate./*Date.*/Year == workDay/*.Date*/.Year &&
     x.BalanceDate./*Date.*/Month == workDay/*.Date*/.Month &&
     x.BalanceDate./*Date.*/Day == workDay/*.Date*/.Day); 

PS: It's always a good practice to manage/unitialize the timezone offset, or use UTC when dealing with date types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM