我想计算两个日期之间的差值,但是如果 "结束日期 "有空,比如第二行和第四行,那么我想放入 "今天"......数据表是这样的。
Hire Date Term Date = "end date"
01/01/2019 05/01/2020
05/04/2018
09/17/2019 03/18/2020
10/19/2018
我是觉得这样的东西可以用,但不是......
If([Term Date]<>NULL THEN DateDiff("year",[Hire Date],[Term Date])
ELSE DateDiff("year",[Hire Date],Today())
END
先谢谢你了!
你可以使用SN(),就是替代Null。
DateDiff('year',[Hire Date] , SN([TermDate],Today() ) )
或者使用case语句而不是IF,因为你的IF语句的格式是不正确的------。If(argument, True, False)
是正确的格式,但在某些时候,案例更容易处理。
Case when [Term Date] is null then DateDiff("year",[Hire Date],Today())
else DateDiff("year",[Hire Date],[Term Date])
end