# COUNTIF for dates



## dmfweb (Jan 6, 2023)

Can I do a countif for a range of dates?  I have a table with hundreds of dates (not exact dates if it matters   Example: 1/6/2023  11:04:41 AM ).  

Can I do a formula for number of dates that are yesterday for example?
I will ultimately end up doing how many are yesterday, 2 days ago and within 7 days... but I can do the rest I think once I can get the first part...  I am not sure if it is because the dates include times....?   any help would be greatly appreciated


----------



## DanteAmor (Jan 7, 2023)

How about:

Dante AmorABC1DateYesterday7 days228/dic/2022 10:20:15 a. m.35330/dic/2022 10:20:15 a. m.401/ene/2023 10:20:15 a. m.503/ene/2023 10:20:15 a. m.606/ene/2023 10:20:15 a. m.706/ene/2023 10:35:36 a. m.806/ene/2023 10:50:57 a. m.907/ene/2023 10:20:15 a. m.1013/ene/2023 10:20:15 a. m.1115/ene/2023 10:20:15 a. m.1217/ene/2023 10:20:15 a. m.Hoja2Cell FormulasRangeFormulaB2B2=COUNTIFS($A2:$A12,">="&TODAY()-1,$A2:$A12,"<"&TODAY())C2C2=COUNTIFS($A2:$A12,">="&TODAY()-7,$A2:$A12,"<"&TODAY())


----------



## kvsrinivasamurthy (Jan 7, 2023)

Try this for 7th Jan 2023.

```
=sumproduct(INT(A2:A12)=Date(2023,1,7))
```


----------



## Peter_SSs (Jan 7, 2023)

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the *best solution often varies by version.* (Don’t forget to scroll down & ‘Save’)


----------



## dmfweb (Jan 7, 2023)

DanteAmor said:


> How about:
> 
> Dante AmorABC1DateYesterday7 days228/dic/2022 10:20:15 a. m.35330/dic/2022 10:20:15 a. m.401/ene/2023 10:20:15 a. m.503/ene/2023 10:20:15 a. m.606/ene/2023 10:20:15 a. m.706/ene/2023 10:35:36 a. m.806/ene/2023 10:50:57 a. m.907/ene/2023 10:20:15 a. m.1013/ene/2023 10:20:15 a. m.1115/ene/2023 10:20:15 a. m.1217/ene/2023 10:20:15 a. m.Hoja2Cell FormulasRangeFormulaB2B2=COUNTIFS($A2:$A12,">="&TODAY()-1,$A2:$A12,"<"&TODAY())C2C2=COUNTIFS($A2:$A12,">="&TODAY()-7,$A2:$A12,"<"&TODAY())


That worked!   Can you tell me how/why it worked?    I have used countifs before, but I can't quite figure out what is happening or the logic


----------



## dmfweb (Jan 7, 2023)

Peter_SSs said:


> I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the *best solution often varies by version.* (Don’t forget to scroll down & ‘Save’)


Done.  Thank you


----------



## Peter_SSs (Jan 7, 2023)

dmfweb said:


> Done. Thank you


Thanks for that. 

I would probably stick with the COUNTIFS but since you have 365, other possibilities are also available.

23 01 08.xlsmABC1DateYesterday7 days228/12/2022 10:20:15 AM16330/12/2022 10:20:15 AM41/01/2023 10:20:15 AM53/01/2023 10:20:15 AM66/01/2023 10:20:15 AM76/01/2023 10:35:36 AM86/01/2023 10:50:57 AM97/01/2023 10:20:15 AM1013/01/2023 10:20:15 AM1115/01/2023 10:20:15 AM1217/01/2023 10:20:15 AMSheet2 (2)Cell FormulasRangeFormulaB2B2=COUNT(FILTER(A2:A12,INT(A2:A12)=TODAY()-1,""))C2C2=LET(d,INT(A2:A12),t,TODAY(),COUNT(FILTER(d,(d<t)*(d>=t-7),"")))


----------

