# Formula Help: Return 0 if the fields are blank, otherwise run formula

I am needing to calculate the days between two dates but if there are no dates, I would like the formula to return the number 0. I would normally use iferror in excel to run this but that isn’t an option on monday.

days({ End Date},{Start Date})

Thank you!

@rrandall

IF(AND({End Date}, {Start Date}), DAYS({End Date}, {Start Date}), 0)

Monday Man ever the genius. How would I apply the same logic to a formula that is doing the same but with times. I have tried a couple of ways but didn’t work:

IF({Dep D2} < {Arr D1 (Rtn)}, HOURS_DIFF({Arr D1 (Rtn)}, {Dep D2}), HOURS_DIFF({Dep D2}, {Arr D1 (Rtn)}))

Thanks.

@Noelie2000

``````IF(AND({Dep D2}, {Arr D1 (Rtn)}),
IF({Dep D2} < {Arr D1 (Rtn)}, HOURS_DIFF({Arr D1 (Rtn)}, {Dep D2}), HOURS_DIFF({Dep D2}, {Arr D1 (Rtn)}))
, 0)
``````

Outstanding that works. I get the same problem when I try to change that field to decimal:

MID({Drive D2-D1Rtn},1,LEN({Drive D2-D1Rtn})-3)+right({Drive D2-D1Rtn},2)/60

Could the same rationale be added to that to return 0 or possibly instead of 0 in the original formula return 00:00 so it is a time.

Sorry is cooking my brain.

@Noelie2000

If you looking to turn the difference into decimal hours, you might try this:

``````IF(AND({H1}, {H2}),
ABS(TIMEVALUE("1/1/1 " & {Dep D2}) - TIMEVALUE("1/1/1 " & {Arr D1 (Rtn)})) * 24
, 0)
``````

1 Like

That just totally made me rethink the way I calculated the columns; reduced the process by half.

Many thanks.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.