2016-08-02 51 views
0

我想能夠將dd添加到custQuery7。也就是說,從值大於3天前的trans_date中減去兩個日期date_paid。然後數一下。如何減去LINQ to SQL中的兩個日期?

 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 
+0

要算什麼? – Hogan

+0

未處理的檢查,我已經將SQL查詢添加到頂端的帖子。 –

回答

2

沒有測試,但你可以這樣做:

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/en-us/library/bb468730(v=vs.110).aspx

+0

謝謝,看起來像那樣的作品。 –