Use of DATEIF Function

Marcie Be

Board Regular
Joined
Jun 25, 2020
Messages
124
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I am using the DATEIF function to stop counting the numbers of days open when a closed date is input in another cell.
I also need the formula to work when the cell with the creation date is blank.
Here is my Formula
AA=DATEDIF($Z4,IF(H4>0,H4,TODAY()),"D")

If Cell $Z4 is empty i.e. there is no creation date the cell AA should be blank/empty

Should I use the OR Function? If so how?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the board. Try:
Code:
=IF($Z4="","",DATEDIF($Z4,IF($H4>0,TODAY(),$H4),"D")
 
Upvote 0
Thank you Jack, for your prompt reply very helpful. Not quite resolved yet, see comments below

=IF($Z4="","",DATEDIF($Z4,IF($H4>0,TODAY(),$H4),"D")

I was one column to the right so the formula I edited too

=IF($AA4="","",DATEDIF($AA4,IF($H4>0,TODAY(),$H4),"D"))

I added in the extra closed bracket on the end

I get a #NUM! error

Something not quite right. Almost but not quite
 
Upvote 0
Try:
Code:
=IF($AA4="","",DATEDIF($AA4,IF($H4>0,TODAY()),"D"))
which is similar to your original formula, nothing specified for the FALSE part within the IF statement.
 
Upvote 0
Try:
Code:
=IF($AA4="","",DATEDIF($AA4,IF($H4>0,TODAY()),"D"))
which is similar to your original formula, nothing specified for the FALSE part within the IF statement.
Thanks again

This now works if there is a data in $H4
I need the formula to work when $H4 is empty as well. A date will not be entered into $H4 until the task is complete.
 
Upvote 0
DATEDIF needs 2 dates to calculate the difference in dates. You're using AA4 and Today(), IF H4 is > 0.
If H4 is not greater than 0, what date should it use instead of Today()?
 
Upvote 0
what date should it use instead of Today()?
If H4 is not greater than Zero this means the task is not complete. The days should keep counting, until task is complete and a date is entered into H4. Once a date is entered into H4 the count should stop as the task is now complete.
Cell $AB4 is counting the number of days the task is open from Creation Date cell $AA4 until task is complete. Completion date entered into cell $H4
 
Upvote 0
Try:
Code:
=IF($H4,IFEERROR(DATEDIF($AA4,TODAY(),"D"),""),$AB4)
 
Upvote 0
=IF($H4,IFEERROR(DATEDIF($AA4,TODAY(),"D"),""),$AB4)
That produces a 0 in cell $AB4. When cells $AA4 & $H4 are empty
$AB4 is also 0 when date entered into $AA4 this is wrong. When a date is input into $AA4, the number of days open should be counted in cell $AB4

The above formula returned a date of 00/01/1900 which I converted to a number by formatting it to general which then converted it to a 0.
Ideally if the formula produces a 0 then I need it to replace the zero with a space so that the cell appears blank, when $AA4 the creation date cell is empty.

Thanks again for all your help. :)
 
Upvote 0

Forum statistics

Threads
1,215,449
Messages
6,124,911
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top