How I can find datediff in month using LINQ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If I understand correctly, you want the number of month boundaries crossed between two specific dates. You don't need LINQ for that; this should work:
// Assuming DateTime startDate, endDate
int monthDiff = ((endDate.Year - startDate.Year) * 12) +
(endDate.Month - startDate.Month);
回答2:
var result = from i in myTable
select SqlMethods.DateDiffMonth(i.DateStart, i.DateEnd);
This will generate sql query with DATEDIFF
function
标签:
linq-to-sql