[英]How to subtract two dates in LINQ to SQL?
我希望能夠將dd添加到custQuery7。 再說一遍,從trans_date減去兩個日期date_paid,其中值大於3天。 然后算那些。
var dd = m.date_paid.Value.Subtract(m.trans_date.Value) > 3;
var custQuery7 = ((from m in DataContext.pu_balance_hists
where m.desc_code == 141
&& m.trans_date.Value.Year == 2016
&& m.trans_date.Value.Month == 5
select m)).Count();
這是我要模仿的SQL查詢:
select COUNT(*) as 'UnprocessedChques' from pu_balance_hist
where desc_code=141 and date_paid-trans_date>3
and YEAR(trans_date)=2016 and MONTH(trans_date)=5
未經測試,但是您可以執行以下操作:
var custQuery7 = ((from m in DataContext.pu_balance_hists
where m.desc_code == 141
&& SqlMethods.DateDiffDay(m.date_paid, m.trans_date) >= 3
&& m.trans_date.Value.Year == 2016
&& m.trans_date.Value.Month == 5
select m)).Count();
https://msdn.microsoft.com/zh-CN/library/bb468730(v=vs.110).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.