开发者

DateDiff in LINQ

开发者 https://www.devze.com 2023-01-07 15:31 出处:网络
How I can find datediff in mon开发者_运维技巧th using LINQ?var result = from i in myTable select SqlMethods.DateDiffMonth(i.DateStart, i.DateEnd);

How I can find datediff in mon开发者_运维技巧th using LINQ?


var result = from i in myTable 
             select SqlMethods.DateDiffMonth(i.DateStart, i.DateEnd);

This will generate sql query with DATEDIFF function


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号