Excel Formula

Copper Contributor

I need to make a formula that will calculate the days beetween two dates if there is a date in the selected cell. If there is not a date in the selected cell, then I would like it to calculate it from one date to today. This is the formula I have so far that I tried to use =IF(NOT(ISBLANK(AB5)),"=DATEDIF(AA5,AB5,"d")","=DATEDIF(AA5,TODAY(),"d")").

When I put this formula in, excel seems to have an issue with "d" but if I remove that, then it will enter "=DATEDIF(AA5,AB5")" or "=DATEDIF(AA5,TODAY()" in the cell. 

I am new to the "IF" function in excel so I could use some help on this. I've also never tried to do a formula in another formula. Any help would be appreciated. 

3 Replies

@Rachel1910 

Try it like this...

 

=IF(NOT(ISBLANK(AB5)),DATEDIF(AA5,AB5,"d"),DATEDIF(AA5,TODAY(),"d"))

@Rachel1910 As a variant:

=IF(ISNUMBER(AB5),AB5-AA5,TODAY()-AA5)

 

@Rachel1910, another variant would be: 

=IF(N(AB5),AB5,TODAY())-AA5