计算工作时间差,扣除非工作时间
在Excel当中编辑一个自定义函数,用来计算工作时段的时间差,精确到秒。
我自己做出来的,共享一下。
1. 周一到周五的8:30-12:00 , 13:00-17:30为工作时间,其他时间为非工作时间
2. 周六、周日为非工作时间
Public Function WorkTimeDiff(Startime As Date, Endtime As Date) As LongDim i As LongDim Temptime As DateDim Temps As LongDim TimeV As DoubleTemps = DateDiff("s", Startime, Endtime)For i = 1 To TempsTemptime = DateAdd("s", i, Startime)Select Case Format(Temptime, "w")Case 2, 3, 4, 5, 6 TimeV = (CDbl(Temptime) - Fix(CDbl(Temptime))) * 48 If (TimeV > 17 And TimeV < 24) Or (TimeV > 26 And TimeV < 35) Then WorkTimeDiff = WorkTimeDiff + 1 End If End SelectNextEnd Function