简体   繁体   中英

Count IF with Date and Time in single Cell (EXCEL)

I have a spreadsheet that lists the date and time of an event in the same cell ( mm/dd/yy h:mm ). I need to find a way to count how many events took place between a certain time range in a Hourly Basis.

I could sum if the cell contains dates only however the cell contains with date which i am unable to get the values.

在此处输入图片说明

Basically, all datas are in cell A , so i need to count how many events happened at 6am, 7am , and so on... as on hourly basis.

Your column A looks like properly formatted date & time value, so its manipulation is easy. If it's not (ie, not date but text) you should first convert it to date value.

=DATE(MID(A2,7,4), MID(A2,4,2), LEFT(A2,2)) + TIME(MID(A2,12,2), MID(A2,15,2), RIGHT(A2,2))

Say this was C2 . Now that column C is date & time, set $D$2 to date to query(ex 2017-03-26 ), E2 to start time(ex 6:00 ), and F2 to end time(ex 7:00 ), then you can count events from 6:00 to 7:00 like this:

=COUNTIFS(C:C,">="&($D$2+E2), C:C,"<"&($D$2+F2))

Sample file is here and its screenshot is below.

在此处输入图片说明

If the times spanned different dates and you still wanted to see how many events happened in a particular hour of the day, you would need an array-type formula, eg if the start time in hours (entered as a normal number) is in C2

=SUMPRODUCT(--(HOUR($A$2:$A$10)=C2))

or if the start hour is entered as a time

=SUMPRODUCT(--(HOUR($A$2:$A$10)=HOUR(C2)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM