本文介绍了两个日期之间的差异,以小时计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var receiveDetails = objDB.GetAllReceivedDetails().Where(a => a.ReceiveDate.Value.Date == DateTime.Now.Date && (((DateTime.Now.Hour) - (a.ReceiveDate.Value.Hour)) <= 1));
上面的代码不能正常工作。如果有人想知道两个日期之间有什么区别那么请回复。
above code is not working.If anyone have idea of making difference between two date then please reply.
推荐答案
DateTime now = DateTime.Now;
var receiveDetails = objDB.GetAllReceivedDetails().Where(a => a.ReceiveDate.Value.Date == now.Date && (now - a.ReceiveDate.Value).TotalHours <= 1);
var receiveDetails = objDB.GetAllReceivedDetails()
.Where(a =>
a.ReceiveDate.Value.Date == DateTime.Now.Date &&
((DateTime.Now - a.ReceiveDate.Value).TotalHours <=1));
希望有所帮助^ _ ^
Andy
Hope that helps ^_^
Andy
TimeSpan difference = firstDateTime - secondDateTime;
double diffInHours = difference.TotalHours
这篇关于两个日期之间的差异,以小时计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!