跳到主要內容

如何在Excel中計算兩個日期之間(週末或節假日除外)的淨工作時間?

在許多公司中,員工是按工作時間支付工資的。 計算一天的淨工作時間很容易,但是如何計算日期範圍內的淨工作時間呢? 為此,本文介紹了在Excel中計算兩個日期(週末和節假日除外)之間的淨工作時間的公式。

計算工作日(不包括週末)

計算工作時間,不包括週末/節假日


箭頭藍色右氣泡 計算工作日(不包括週末)

在這一部分中,我將介紹用於計算兩個日期時間(不包括週末)之間的工作日的公式。

1.選擇兩個單元格,分別輸入開始日期時間和結束日期時間,然後右鍵單擊以選擇 單元格格式 形成上下文菜單。 看截圖:
doc網絡工作時間1

2。 在裡面 單元格格式 對話框中單擊 聯繫電話 選項卡,然後選擇 習俗 形成 類別 列表,然後輸入 m / d / yyyy h:mm 類別 右側的文本框。 看截圖:
doc網絡工作時間2

3。 點擊 OK。 然後分別在兩個單元格中輸入開始日期時間和結束日期時間。 看截圖:
doc網絡工作時間3

4.在這兩個單元格旁邊的單元格中,例如C13,輸入此公式 =NETWORKDAYS(A13,B13)-1-MOD(A13,1)+MOD(B13,1),然後按 Enter 鍵,您將獲得具有自定義格式的結果,選擇結果單元格,然後單擊 首頁 標籤,然後轉到 數字格式 列表以選擇常規以將其格式化為正確的格式。 看截圖:
doc網絡工作時間4


箭頭藍色右氣泡 計算工作時間,不包括週末/節假日

如果要計算不包括週末或節假日的淨工作時間,可以按以下方法進行:

計算不包括週末的淨工作時間

1.選擇兩個單元格並將其格式化為自定義格式m / d / yyyy h:mm,然後輸入開始日期時間和結束日期時間。 看截圖:
doc網絡工作時間5

doc網絡工作時間6

2.在單元格(例如C2)旁邊,輸入此公式,
=(NETWORKDAYS(A2,B2)-1)*("17:30"-"8:30")+IF(NETWORKDAYS(B2,B2),MEDIAN(MOD(B2,1),"17:30","8:30"),"17:30")-MEDIAN(NETWORKDAYS(A2,A2)*MOD(A2,1),"17:30","8:30"),
Enter 鍵,然後您將得到一個數字字符串。 看截圖:
doc網絡工作時間7

3.右鍵單擊數字字符串,然後單擊 單元格格式 從上下文菜單中 單元格格式 對話框中選擇 習俗 形成 類別 在下面列出 數量r標籤,然後輸入 並[h]:毫米 進入類型文本框。 看截圖:
doc網絡工作時間8

4。 點擊 OK。 現在將計算兩個日期之間(週末除外)的淨工作時間。
doc網絡工作時間9

尖端:在公式中,A2是開始日期時間,B2是結束日期時間,每天的8:30和17:30是常規開始時間和結束時間,您可以根據需要進行更改。

計算淨工作時間,不包括週末和節假日

1.與上述相同,選擇兩個單元格並將其格式化為自定義格式 m / d / yyyy h:mm,然後輸入開始日期時間和結束日期時間。
doc網絡工作時間10

2.選擇一個空白單元格,然後在其中輸入假日日期,這裡我有3個假日,並分別在H1:H3中鍵入。 看截圖:
doc網絡工作時間11

3.選擇一個空白單元格,它將放置計數結果,例如C2,
=(NETWORKDAYS.INTL(A2,B2,11,H$1:H$3)-1)*("17:30"-"8:30")+IF(NETWORKDAYS.INTL(B2,B2,11,H$1:H$3),MEDIAN(MOD(B2,1),"8:30","17:30"),"17:30")-MEDIAN(NETWORKDAYS.INTL(A2,A2,11,H$1:H$3)*MOD(A2,1),"8:30","17:30"),
並按下 Enter 鍵,您將獲得一個數字字符串,並將其格式化為自定義格式 並[h]:毫米。 看截圖:
doc網絡工作時間12

尖端:在公式中,A2是開始日期時間,B2是結束日期時間,每天的8:30和17:30是一般的開始時間和結束時間,H1:H3是假日單元格,您可以更改它們根據需要。

在Excel中輕鬆地將天/年/月/小時/分鐘/秒添加到日期時間

假設您在一個單元格中有一個日期時間格式數據,現在您需要在該日期中添加若干天,年,月,小時,分鐘或秒。 通常,使用公式是所有Excel用戶的第一種方法,但是很難記住所有公式。 用 Excel的Kutools日期和時間助手 實用程序,您可以輕鬆地將天,年,月,小時,分鐘或秒添加到日期時間,此外,您可以計算出日期差或基於給定生日的年齡,而無需記住任何公式。 點擊即可獲得 30 天的全功能免費試用!
doc第二小時添加小時
 
Kutools for Excel:擁有300多個便捷的Excel加載項,可以在30天內免費試用。

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (67)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This formula is very good. Does anyone know how I can convert this to SQL query?
This comment was minimized by the moderator on the site
it works
how to add lunch break?
This comment was minimized by the moderator on the site
This is very good, what if the shift time spans over 2 days (start time 17:00 to 02:00 next day)
This comment was minimized by the moderator on the site
Hi
Have recieved any update regarding for your questions because I am also finding for same
This comment was minimized by the moderator on the site
Can anyone help me how the formula would be if the work hours are from 8:00 pm to 5:00 am (20:00 to 5:00)?
This comment was minimized by the moderator on the site
Tried the same formula but it's showing negative values.
This comment was minimized by the moderator on the site
Anyone need this formula but for graveyard or night shift schedule?
This comment was minimized by the moderator on the site
Why is the Median function used in this formula? what is calculating
This comment was minimized by the moderator on the site
Hey, thanks for this formula.

But can we apply this formula for same dates.

For ex,
if start date and time is
" 15/11/20 11:10AM" and end date and time is "15 /11/20 11:25AM"
This comment was minimized by the moderator on the site
Hi, Pooja, use formula (M1 is the start time,M2 is the end time)
=(NETWORKDAYS(M1,M2)-1)*("17:30"-"8:30")+IF(NETWORKDAYS(M2,M2),MEDIAN(MOD(M2,1),"17:30","8:30"),"17:30")-MEDIAN(NETWORKDAYS(M1,M1)*MOD(M1,1),"17:30","8:30")
and format the result cell as time.
This comment was minimized by the moderator on the site
Hi, Sunny, thank you so much, this works perfectly now.
This comment was minimized by the moderator on the site
Hi the formula below works well with me to calculate the tame a task is taking from start to finish excluding a standard weekends of Saturday and Sunday off.
=(NETWORKDAYS(I7,J7)-1)*("18:00"-"8:30")+IF(NETWORKDAYS(J7,J7),MEDIAN(MOD(J7,1),"18:00","8:30"),"18:00")-MEDIAN(NETWORKDAYS(I7,I7)*MOD(I7,1),"18:00","8:30")

However, on Friday we would like to consider 3 working hours only (9:00-12:00), how can I insert it within the formula please? any idea?
This comment was minimized by the moderator on the site
Hi, Pierre, I have modified the formula:
=((NETWORKDAYS(A1,B1)-1)*("18:00"-"8:30")+IF(NETWORKDAYS(B1,B1),MEDIAN(MOD(B1,1),"18:00","8:30"),"18:00")-MEDIAN(NETWORKDAYS(A1,A1)*MOD(A1,1),"18:00","8:30"))-INT((WEEKDAY($A$1- 6)-$A$1+$B1)/7)*(("18:00"-"8:30")-("12:00"-"9:00"))
This comment was minimized by the moderator on the site
Thank you Sunny, but honestly the updated formula did not give the results properly, not sure if it requires additional adjustment:
Monday - Thursday 8:30-18:00 (working hours)
Friday 9:00-12:00 (working hours)
Saturday - Sunday Off
thank you
This comment was minimized by the moderator on the site
Hi, Pierre, I have tested the formula, it works for me. In the formula:
A1 is the start datetime, B1 is the end datetime, and both of the datetime cells are formated as mm/dd/yy hh:mm, then the result you need to format it as time format: 37:30:55.
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-calculate-specific-work-hour.png
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-calculate-specific-work-hour-2.png
This comment was minimized by the moderator on the site
hi sunny,

I have used the formulla and it is working well except for friday hald day calculation showing in negative hours. Kindly suggest

=((NETWORKDAYS(P9,R9,1)-1)*("15:00"-"07:00")+IF(NETWORKDAYS(R9,R9),MEDIAN(MOD(R9,1),"15:00","07:00"),"15:00")-MEDIAN(NETWORKDAYS(P9,P9)*MOD(P9,1),"15:00","07:00")-INT((WEEKDAY(P9-6)-P9+R9)/7)*(("15:00"-"7:00")-("11:30"-"7:00")))

Start time: 1/12/2024 11:51:02 AM
End Time: 1/12/2024 11:51:13 AM
Result: -3:30:00

Thanks
Nishanth
This comment was minimized by the moderator on the site
Dear all, I would like to ask you for help, I tried this formula for counting working hours between days (without weekends and holidays), but I receive the #Value! error.I formatted the cells as well.
 Start date in A2:  24.11.2021 11:05  <span style="letter-spacing: 0.2px; color: inherit; font-family: inherit; font-style: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit;">   1.12.2021 11:05</span>Workday start in C2:    6:00Workday end  in D2:  18:00Holidays in E2 till E10:
1/1/21
4/2/21
4/5/21
5/1/21
5/13/21
5/24/21
10/3/21
12/25/21
12/26/21
    
I used the following formula:   <span style="letter-spacing: 0.2px; color: inherit; font-family: inherit; font-style: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit;">#Value! error, can you please advise?</span>
This comment was minimized by the moderator on the site
Hello Sir,
My predecessor has set below formula.I am not getting  what is "Holidays[#All]", not getting where he has set this.
Please let me know.....


=ABS(IF([@Priority]<3,settings!$F$2-K3,(((NETWORKDAYS(K3,settings!$F$2,Holidays[#All]))*((settings!$B$3-settings!$B$2)*24)-IF(AND(NETWORKDAYS(K3,K3,settings!$D$2:settings!$D$33)>0,(K3-INT(K3))*24>(settings!$B$2-INT(settings!$B$2))*24,(K3-INT(K3))*24<(settings!$B$3-INT(settings!$B$3))*24),((K3-INT(K3))*24)-((settings!$B$2-INT(settings!$B$2))*24),0)-IF(AND(NETWORKDAYS(settings!$F$2,settings!$F$2,settings!$D$2:settings!$D$33)>0,(settings!$F$2-INT(settings!$F$2))*24<(settings!$B$3-INT(settings!$B$3))*24,(settings!$F$2-INT(settings!$F$2))*24>(settings!$B$2-INT(settings!$B$2))*24),((settings!$B$3-INT(settings!$B$3))*24)-((settings!$F$2-INT(settings!$F$2))*24),0)-IF(AND(NETWORKDAYS(K3,K3,settings!$D$2:settings!$D$33)>0,(K3-INT(K3))*24>(settings!$B$3-INT(settings!$B$3))*24),(settings!$B$3-settings!$B$2)*24,0)-IF(AND(NETWORKDAYS(settings!$F$2,settings!$F$2,settings!$D$2:settings!$D$33)>0,(settings!$F$2-INT(settings!$F$2))*24<(settings!$B$2-INT(settings!$B$2))*24),(settings!$B$3-settings!$B$2)*24,0))/24)))
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations