跳到主要內容

如何計算兩個日期之間的天數,週數,月數或年數?

您是否考慮過在Excel中給定兩個日期之間計算多少天,幾週,幾月或幾年? 本教程可以幫助您盡快完成以下操作。


用公式計算兩個日期之間的天數

要計算兩個給定日期之間的天數,請使用以下公式:

1。 在要獲取結果的空白單元格中輸入以下任一公式:

=DATEDIF(A2,B2,"D")
=B2-A2

備註:在以上公式中, A2 是開始日期單元格,並且 B2 是結束日期單元格。

2。 然後,將填充手柄向下拖動到要應用此公式的單元格上,並且已經計算了天數,請參見屏幕截圖:


用公式計算兩個日期之間的星期數

要計算兩個日期之間的周數,可以使用下面的方便公式,只需從結束日期中減去開始日期並除以7。

1。 在空白單元格中輸入以下任一公式:

=(DATEDIF(A2,B2,"D")/7)
=(B2-A2)/7

備註:在以上公式中, A2 是開始日期單元格,並且 B2 是結束日期單元格。

2。 然後,向下拖動填充手柄以填充此公式,您將獲得以十進制數字表示的星期,請參見屏幕截圖:

  • 保養竅門如果要獲取兩個日期之間的整週數,請應用以下公式:
  • = ROUNDDOWN((DATEDIF(A2,B2,“ d”)/ 7),0)
    = INT((B2-A2)/ 7)


計算天,週,月,年等兩個日期之間的各種差異。

要記住的公式太多 Excel的Kutools's 日期和時間助手 功能,您可以根據需要快速獲得兩個日期之間的各種差異結果,而無需記住任何公式,例如周+天,月+周等。 點擊下載Kutools for Excel!

Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!


用公式計算兩個日期之間的月數

如果要確定兩個日期之間的月數,可以使用此DATEDIF函數。

1。 請在要輸出結果的空白單元格中輸入以下公式:

=DATEDIF(A2,B2,"m")

備註:在以上公式中, A2 是開始日期單元格,並且 B2 是結束日期單元格。

2。 然後,向下拖動填充手柄以填充此公式,您將獲得給定兩個日期之間的完成月份數,請參見屏幕截圖:

  • 保養竅門如果要獲取兩個日期之間的整週數,請應用以下公式:
  • = DATEDIF(A2,B2,“ m”)&“ months”&DATEDIF(A2,B2,“ md”)&“ days”


用公式計算兩個日期之間的年數

使用上面的DATEDIF函數,您還可以計算兩個日期之間的年數。

1。 將以下公式應用於空白單元格:

=DATEDIF(A2,B2,"y")

備註:在以上公式中, A2 是開始日期單元格,並且 B2 是結束日期單元格。

2。 然後,將填充手柄向下拖動到要應用此公式的單元格上,所有年數都已如下圖所示進行了計算:


用公式計算兩個日期之間的年月日數

有時,您需要確切地知道兩個日期之間有多少年,幾個月和幾天,在這種情況下,以下長公式可能會對您有所幫助。

1。 在空白單元格中,輸入或複制以下公式:

=DATEDIF(A2, B2, "y") &" years "&DATEDIF(A2, B2, "ym") &" months " &DATEDIF(A2, B2, "md") &" days"

備註:在以上公式中, A2 是開始日期單元格,並且 B2 是結束日期單元格。

2。 然後,拖動填充手柄以填充此公式,並立即計算日期之間的特定年,月和日數,請參見屏幕截圖:


利用強大的功能計算幾天,幾週,幾個月,幾年中兩個日期之間的各種差異

如果您有,可能是您對上述公式感到惱火 Excel的Kutools,其 日期和時間助手 功能,您可以根據需要快速獲取兩個日期之間的各種差異結果,例如周+天,月+周等。

注意:要應用此 日期和時間助手,首先,您應該下載 Excel的Kutools,然後快速輕鬆地應用該功能。

安裝後 Excel的Kutools,請這樣做:

1。 單擊要在其中查找結果的單元格,然後單擊 庫工具公式助手 > 日期和時間助手,請參見屏幕截圖:

2。 在 日期和時間助手 對話框中,進行以下操作:

  • 格紋 差異 選項從 類別 部分;
  • 參數輸入 在文本框中,分別選擇包含開始日期和結束日期的單元格;
  • 然後,根據需要選擇輸出結果類型。 例如,如果要獲取兩個日期之間的年,月,周和天數,則只需選擇 年+月+週+天.

3。 完成設置後,請點擊 OK 按鈕,您將獲得第一個計算結果,然後,只需將填充手柄向下拖動到要應用此公式的單元格,您將根據需要獲得以下結果:

點擊下載Kutools for Excel並立即免費試用!


更多有關日期和時間的文章:

  • 在Excel中計算午夜後的時間之間的小時數
  • 假設您有一個時間表來記錄您的工作時間,則A列中的時間是今天的開始時間,B列中的時間是第二天的結束時間。 通常,如果您直接減去“ = B2-A2”來計算兩次之間的時間差,則不會顯示正確的結果,如左圖所示。 如何在Excel中正確計算午夜後兩次之間的小時數?
  • 計算兩個日期之間的天數/工作日/週末數
  • 您是否曾經需要計算過Excel中兩個日期之間的天數? 有時候,您可能只想計算兩個日期之間的工作日,有時,您只需要計算兩個日期之間的周末天。 在特定條件下,您如何計算兩個日期之間的天數?

最佳辦公生產力工具

🤖 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 (45)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Dateif formula how to input?
This comment was minimized by the moderator on the site
Hi I am trying to build up a salary report where i need to split a person salary by month if they completed that full month , and if their start or end date is after the beginning or the did of the month then calculate that month based on the network days worked. the problem I am getting when using the theses date formulas is that are not showing the correct completed month only. for example.

Start Date End Date
07/09/2022 11/01/2023

this should be 3 months and 26 days (18 working days in September and 8 working days in Jan 2023) = DatedIf formula is showing 4
Can anyone help?


thanks,
Charlotte
This comment was minimized by the moderator on the site
Quisiera saber, si podría calcular cuántos martes hay entre dos fechas; por ejemplo, en tres años o no es posible
Gracias de antemano por su colaboración
This comment was minimized by the moderator on the site
Hello, Pilar,
To get the number of a specific weekday, you can apply the below formula:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(A2&":"&B2)))=3))


Note: A2 is the start date, B2 is the end date, and the number 3 indicates Tuesday, 1 to 7 indicates from Sunday to Saturday, you can change the number to your need.

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Muchísimas gracias por su ayuda
This comment was minimized by the moderator on the site
Love Kutools! I purchased years ago and still visit the extednoffice.com site when I need fast solutions!
This comment was minimized by the moderator on the site
Avenger vs Marvell
perhitungan permainan roulette
perhitungan permainan sicbo
This comment was minimized by the moderator on the site
How can obtain age from two DOB. Eg- i need to calculate the age from DATE of Birth till the Date of Treatment was started
This comment was minimized by the moderator on the site
how to obtain matching no of months between two sets of dates ?
This comment was minimized by the moderator on the site
What is the formula for 01/05/2017 13:01:20 minus 01/05/2017 08:59:27 to get the total hours.
This comment was minimized by the moderator on the site
I need the following and cannot figure out the formula I have been given the date of birth, date of exam. I need a third date, (record purge date) that has the following rules; IF they are 18 or over by exam date, the purge date will be 7 years from exam date IF they are under 18 by exam date, the purge date would be 7 years from when they turn 18
This comment was minimized by the moderator on the site
Thank You so much for your way. 2017 calendar printable
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