Jun 04, 2021 01:46 PM
I am trying and very close to getting this to work
IF(DATETIME_FORMAT({Last Time Done}, ‘YYYY’ = 0000), DATETIME_DIFF(TODAY(), {Last Time Done},‘days’), “Never Done”)
I can’t get it to say neverd one when last time done year matches 0000
Jun 04, 2021 08:19 PM
Hi! I figured out that there are a few things you can change in your code:
Logic
The ‘IF’ clause work in this way:
IF(condition, what to show if condition is true, what to show if condition is false)
Therefore, you should put “Never Done” at the first bit instead of the final bit if you want “Never Done” to be shown when the year of {Last Time Done} matches 0000.
Syntax
In your code, the ‘)’ is put at a wrong place. You should first close the DATETIME_FORMAT to make it a string,THEN you compare the string to “0000”. Also, I think you can “quote” 0000 to show that it is a string but not a number. (However leaving it unquote also doesn’t matter)
To sum up, use the code below instead:
IF(DATETIME_FORMAT({Last Time Done},'YYYY')="0000","Never Done",DATETIME_DIFF(TODAY(),{Last Time Done},'days'))
IF({Last Time Done}=BLANK(),"Never Done",DATETIME_DIFF(TODAY(),{Last Time Done},'days'))
Just for reference. Have fun!
Jun 05, 2021 06:09 AM
Good call. If a date field is blank, any date-related functions will cause the formula to throw an error. A slightly easier way to check for an empty date field is to wrap the NOT()
function around the field reference itself. Keeping the same logical order, that variation would look like this:
IF(NOT({Last Time Done}), "Never Done", DATETIME_DIFF(TODAY(),{Last Time Done},'days'))
You could also remove NOT()
, and reverse the order of the other two arguments:
IF({Last Time Done}, DATETIME_DIFF(TODAY(),{Last Time Done},'days'), "Never Done")