LINQ中的DateDiff [英] DateDiff in LINQ

查看:95
本文介绍了LINQ中的DateDiff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用LINQ在月份中找到datediff?

How I can find datediff in month using LINQ?

推荐答案

如果我理解正确,则需要两个特定日期之间的月界限.您不需要LINQ.这应该工作:

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

这篇关于LINQ中的DateDiff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆