inconsistency in COUNTIF of time values

guardog

New Member
Joined
May 5, 2014
Messages
13
Here's the simplified situation

ABCD
1Time startTime EndDuration
208:40 AM08:55 AM00:15=COUNTIF(C2:C3,"=0:15")
304:20 PM04:35 PM00:15

<tbody>
</tbody>

PROBLEM:
The countif returns only "1", this kinda puzzles me

I've tried applying *1440 to convert C2 and C3 into number of minutes (changed the Cell Formatting into General)

ABCD
1Time startTime EndDuration
208:40 AM08:55 AM15=COUNTIF(C2:C3,"=15")
304:20 PM04:35 PM15

<tbody>
</tbody>
PROBLEM:
The countif returns "0", err what?

Am I encountering some unknown limitation of countif here?

PURPOSE OF REFERRAL:
I am hoping to get the countif = 2 in the first situation

Many thanks in advance.

ADDITIONAL INFORMATION:
Using INT() in C2 and C3 after *1440 (situation 2) gives 14 and 15
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I've had to deal with this before. For some reason excel is not able to see the precise match on a specific timestamp after a subtraction. I think it has something to do with excel's limitation on significant figures.

The work around is to toss in a round statement. For example in C2:
=ROUND((B2-A2)*1440,0)
 
Upvote 0
It is definitely a precision problem. When you converted to an integer with *1440, change the cell formatting to many decimal places to see this for yourself.

The above solution works or if you want something a little closer to your original formula, this will work (use Control + Shift + Enter to make it function):

Code:
=SUM(IF(MINUTE(C2:C3) = 15, 1, 0))

Alternatively, change your duration column to this and use your old COUNTIF() formula:

Code:
=TIME(HOUR(C3) - HOUR(B3), MINUTE(C3) - MINUTE(B3), 0)

Warning: This ignores seconds by default but can be modified to include them.
 
Last edited:
Upvote 0
You know on second thought, it's probably better to round to the nearest second instead of minute.

In C2, formatted as mm:ss
=ROUND((B2-A2)*86400,0)/86400

In D2:
=COUNTIF($C$2:$C$3,(15/1440))
 
Upvote 0
Thank you guys for the input.

I used
Code:
[COLOR=#333333]=ROUND((B2-A2)*1440,0)[/COLOR]
Which is good enough for my data as it doesn't have seconds, at least for now there's no more odd 1 minute addition (or minus) when calculating straightforward duration such as in between 0800 and 0830
Will switch to the seconds conversion if odd results start to appear :biggrin:

Tried ROUNDUP((B2-A2)*1440,0) before this, which resulted in 1 minute addition (i.e. 31 minutes for 0800 to 0830)
ROUND seems to be better in this case.

CASE RESOLVED
 
Upvote 0

Forum statistics

Threads
1,215,376
Messages
6,124,594
Members
449,174
Latest member
chandan4057

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