日期之间的差异月 [英] Months difference between dates

查看:123
本文介绍了日期之间的差异月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
   href="http://stackoverflow.com/questions/1525990/difference-in-months">差异

大家好:

我们如何计算使用LINQ两个日期之间的月差?我可以用找到天差:

(p.Account.StateChangeDate.Date - DateTime.Now.Date).Days< 4

但有好几个月没办法。

请建议。

解决方案

尝试在几个月 <差异/ P>


选择你想从这个问题使用的算法。

然后,如果您使用的是LINQ2SQL,那么几乎所有的这些都将被映射到数据库中的 DATEPART 键入操作(我认为)。

另外,您可以使用函数像的 http://www.sqlmag.com/article/sql-server/calculating-month-difference.aspx - 并且可能再暴露,要LINQ2SQL作为一个函数

Possible Duplicate:
Difference in months

Hi all:

how can We calculate the months difference between two dates using LINQ ? I can find days difference using:

(p.Account.StateChangeDate.Date - DateTime.Now.Date).Days < 4

but there is no option for months.

Please suggest.

解决方案

Try Difference in months


Pick the algorithm you want to use from that question.

Then, if you are using Linq2Sql, then almost all of those will get mapped back to the database as DATEPART type operations (I think).

Alternatively you could do the calc in SQL using a function like in http://www.sqlmag.com/article/sql-server/calculating-month-difference.aspx - and could then expose that to Linq2Sql as a function

这篇关于日期之间的差异月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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