# Calculating Number of Days (Date Calculation)

#### Pesopakis

##### New Member
I am trying to calculate number of days record is "open". If no end date is available I am using Today's Date for the calculation.

3 columns in my example

[P] = Start Date
[Q] = End Date
[R] = Days Record Open Formula:
=IF(AND(P2<>"", Q2<>""), (Q2-P2), IF(AND(P2<>"", Q2=""), (TODAY()-P2), 0))

Everything calculates correct. But... when a new row is added to the table, column [R] shows "44248". I would like it to show "0".
However, If I enter a value in column [P], then immediately delete it... column [R] then shows "0" as I want it. Why do I have to trigger it? Can I make this default to zero when a new row is added to the table before any data is initially inputted for [P] and [Q] ?

Thanks,

#### Attachments

• ExcelQuestion.jpg
178.6 KB · Views: 9

### Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

#### Zot

##### Well-known Member
Maybe something is wrong in you sheet. Do you have on status bar stating there is circular reference?

#### Peter_SSs

##### MrExcel MVP, Moderator
Welcome to the MrExcel board!

If you have a situation as shown in your image where P2 appears to be blank, if you go to a blank cell elsewhere in the worksheet and enter this formula, what does it return?
=LEN(P2)

I'm wondering if column P contains zeros that are hidden by conditional formatting or by a custom cell format?

Alternatively you could try this formula
Excel Formula:
``=IF(AND(P2>0,Q2>0),Q2-P2,IF(AND(P2>0,Q2=0),TODAY()-P2,0))``

#### Saba Sabaratnam

##### Board Regular
or there are some zeros in P column. if so, you may want to try this formula.

=IF(AND(COUNTIFS(P2,">="&DATE(1900,1,1),P2,"<"&TODAY())>0,COUNTIFS(Q2,">="&DATE(1900,1,1),Q2,"<"&TODAY())>0), (Q2-P2), IF(AND(COUNTIFS(P2,">="&DATE(1900,1,1),P2,"<"&TODAY())>0, Q2=""), (TODAY()-P2), 0))'

it will ignore or text values in Column P as shown below.

Kind regards

Saba

#### Pesopakis

##### New Member
Thank you both. A combination of the two i think will get me where I want to be. I appreciate the help.

#### Peter_SSs

##### MrExcel MVP, Moderator
Cheers. Hope it works out for you.

Did you determine whether zeros in column P (hidden or otherwise) were the problem?

Replies
3
Views
283
Replies
6
Views
253
Replies
10
Views
326
Replies
3
Views
81
Replies
5
Views
191

### Forum statistics

1,127,308
Messages
5,623,884
Members
416,000
Latest member
Sovereign maphoso

### 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.

### Which adblocker are you using?

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

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