Get the Difference between two date-time cells

2019-09-21 07:03发布

I need to get the difference between two date-time cells in hours considering only weekdays.

Example:

25/02/2018 16:00:00 | 26/04/2018 09:00:00 | 19:00:00

2条回答
Viruses.
2楼-- · 2019-09-21 07:25

=( COUNTIF(ARRAYFORMULA( WEEKDAY(ROW(INDIRECT("a1:a"&INT(B1)-int(A1)-1))+ int(A1), 2) ), "<6") + IF(WEEKDAY(B1,2)<6,B1 - INT(B1),0) - if(WEEKDAY(A1,2)<6,A1-INT(A1),0) )*24

counts:

  • days not weekends, except date1 and date2
  • time of day2 if not a weekend
  • minus time of day 1 if not a weekend.
查看更多
Juvenile、少年°
3楼-- · 2019-09-21 07:32

Using network days:

=(NETWORKDAYS(A1,B1)-IF(WEEKDAY(A1,2)<6,MOD(A1,1))-IF(WEEKDAY(B1,2)<6,1-MOD(B1,1)))*24

This says count working days from first date to second date inclusive.

If first date is a working day, subtract hours not worked before start time.

If second date is a working day, subtract hours not worked after finish time.

Strictly speaking, you should also check that start datetime is before finish datetime.

查看更多
登录 后发表回答