因此,我尝试编写一个函数来显示两个日期之间的差异。
我目前正在使用以下公式:
=DATEDIF(D2,E2,"y")&" Years, "&DATEDIF(D2,E2,"ym")&" Months, "&DATEDIF(D2,E2,"md")
这是我的桌子:
+------------+-----------------+----------------------------+
| Date Hired | Date Terminated | Length of Employment |
+------------+-----------------+----------------------------+
| 10/11/2010 | 10/20/2010 | 0 Years, 0 Months, 9 Days |
| 10/12/2010 | 01/28/2015 | 4 Years, 3 Months, 16 Days |
| 10/13/2010 | 05/07/2015 | 4 Years, 6 Months, 24 Days |
| | | |
+------------+-----------------+----------------------------+
我不确定如何在函数中添加一个部分,指出如果结果小于某个时间段(比如 6 个月),则结果将显示:“小于 6 个月”。
因此使用上面的例子:
+------------+-----------------+----------------------------+
| Date Hired | Date Terminated | Length of Employment |
+------------+-----------------+----------------------------+
| 10/11/2010 | 10/20/2010 | Less than 6 Months |
| 10/12/2010 | 01/28/2015 | 4 Years, 3 Months, 16 Days |
| 10/13/2010 | 05/07/2015 | 4 Years, 6 Months, 24 Days |
| | | |
+------------+-----------------+----------------------------+
我该如何将其添加到上述公式中?
答案1
只需将其放入 if 中,检查 6 个月后 -
=IF((E2-D2)>180,DATEDIF(D2,E2,"y")&" Years, "&DATEDIF(D2,E2,"ym")&" Months, "&DATEDIF(D2,E2,"md"),"Less than 6 Months")