【发布时间】:2019-09-11 08:09:26
【问题描述】:
我有两个日期字段,我需要计算这两个日期之间的月差,我该怎么做。下面是我的公式
(start.Year * 12 + start.Month) - (end.Year * 12 + end.Month);
预期结果
Start Date End Date Need to get output as
08/28/2019 09/02/2019 1
06/01/2019 09/02/2019 4
01/02/2019 03/02/2019 3
01/02/2019 03/05/2019 3
【问题讨论】:
-
您的标题说您想在 C# 中执行此操作,但您已标记 jQuery - 那么它是什么?无论哪种情况,我都 100% 确定这个问题已经有了答案
-
我已经尝试过了,但我没有得到预期的结果
-
来自here:
For example, should dates like July 5, 2009 and August 4, 2009 yield one month or zero months difference? If you say it should yield one, then what about July 31, 2009 and August 1, 2009? Is that a month? Is it simply the difference of the Month values for the dates, or is it more related to an actual span of time?。这是非常重要的! -
你应该告诉我们你得到了什么输出。它应该是结束开始,而不是开始结束。
标签: datediff