简体   繁体   English

Excel公式可计算年和月的日期差

[英]Excel formula to calculate date difference in years and months

I'm trying to come up with an Excel formula that will calculate the difference in years and months between a date in the past and today. 我正在尝试提出一个Excel公式,该公式将计算过去和今天的日期之间的年和月差异。

For example, the following tells me the number of days between a cell and now: 例如,以下内容告诉我一个单元格与现在之间的天数:

=INT((TODAY()-C2))

But I then need to format that value as Year and Month(s). 但是然后我需要将该值的格式设置为Year and Month(s)。

Obviously I'm no expert in Excel and appreciate any help! 显然,我不是Excel方面的专家,不胜感激!

Thanks in advance, 提前致谢,

Dan

Alas, what I did was a simple diff and got a result in year and percent, which will work fine: ,我所做的只是一个简单的比较,并得出了年份和百分比的结果,可以很好地工作:

=((TODAY())-(D2))/365

The DATEDIF was a total disaster, with really odd, inconsistent results. DATEDIF完全是一场灾难,结果确实很奇怪,不一致。

Thanks for all the suggestions though! 谢谢所有的建议!

Looking at the Microsoft Office knowledgebase , I see a YEAR function that may be used: 查看Microsoft Office知识库 ,我看到可以使用的YEAR函数:

A1: 1-Jan-2014
A2: 4-Dec-2016
A3: =YEAR(A2)-YEAR(A1) # will yield 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM