Excel - day/date/time to determine peak/offpeak

混江龙づ霸主 提交于 2020-01-06 05:08:29

问题


I'm trying to determine from a .csv file output (below) if the date/time meets our criteria for peak or off-peak. Peak/off-peak is determined by the day of the week and time. I'm trying to build a formula in excel that lets me know if each date/time is peak or off-peak. I have been using the text to column feature to put the data into two cells then use the TEXT function to determine day of the week in a new cell, then filter feature to input peak/off-peak. This is very manual and inefficient. Thanks in advance.

Peak equals:

- mon, tue, wed thurs, fri and hour 6:00-21:00

Off-peak equals:

- sat, sun and hour 0:00-23:00 
- mon, tue, wed thurs, fri and hour 0:00-5:00 and 22:00-23:00 

File output:

8/15/2017 0:00
8/15/2017 1:00
8/15/2017 2:00
8/15/2017 3:00

Seeking Outcome:

Date/Time       peak/off-peak
8/15/2017 0:00  off-peak
8/15/2017 1:00  off-peak
8/15/2017 2:00  off-peak
8/15/2017 3:00  off-peak
8/15/2017 4:00  off-peak
8/15/2017 5:00  off-peak
8/15/2017 6:00  peak
8/15/2017 7:00  peak
8/15/2017 8:00  peak
8/15/2017 9:00  peak
8/15/2017 10:00 peak
8/15/2017 11:00 peak
8/15/2017 12:00 peak
8/15/2017 13:00 peak
8/15/2017 14:00 peak
8/15/2017 15:00 peak
8/15/2017 16:00 peak
8/15/2017 17:00 peak
8/15/2017 18:00 peak
8/15/2017 19:00 peak
8/15/2017 20:00 peak
8/15/2017 21:00 peak
8/15/2017 22:00 off-peak
8/15/2017 23:00 off-peak

回答1:


You can write the following formula in the B1 cell, where A1 is the cell containing the Date/Time:

=IF(AND(WEEKDAY(A1,2)<=5,WEEKDAY(A1,2)>=1,A1-INT(A1)>=0.25,A1-INT(A1)<=0.875),"peak","off-peak")

The part WEEKDAY(A1,2)<=5,WEEKDAY(A1,2)>=1 checks if the day is between Mon and Fri and the part A1-INT(A1)>=0.25,A1-INT(A1)<=0.875 checks if the hour is between 06:00 and 21:00. If every conditions are TRUE, the formula shows "peak" otherwise it shows "off-peak".



来源:https://stackoverflow.com/questions/46346612/excel-day-date-time-to-determine-peak-offpeak

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!