简体   繁体   English

Excel 中的 Dateif 和 If 语句

[英]Datedif and If statement in Excel

I want to create an Excel formula that allows me to calculate the datedif of the month (ie Date of Expiry - Today's Date).我想创建一个 Excel 公式,允许我计算当月的 datedif(即到期日期 - 今天的日期)。 Which I have done as seen below:我所做的如下所示:

在此处输入图片说明

This is my formula:这是我的公式:

=IFERROR(DATEDIF($F$1,C4,"m") & " Months", "Already Expired")

However, I want a formula that can take note of the (s) in Months if the months left is only 1 Month.但是,如果剩下的月份只有 1 个月,我想要一个公式可以记录月份中的 (s)。 (Ie I do not want the s behind the Months if the "m" in datedif is just 1 month difference.) How do I achieve that? (即,如果 datedif 中的“m”只是 1 个月的差异,我不想要 Months 后面的 s。)我如何实现这一点?

I would write the unit into the cell format, not the formula.我会将单位写入单元格格式,而不是公式。 The formula should produce an integer and the cell format should be Custom [=1]0 "month";0 "months" .公式应生成一个整数,单元格格式应为Custom [=1]0 "month";0 "months"

To test, format a cell as described above and enter any number.要进行测试,请按上述方式格式化单元格并输入任意数字。 The cell will display the number and the word "moth" or "months", depending upon the value you entered.单元格将显示数字和单词“moth”或“months”,具体取决于您输入的值。

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

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