Calculate the Years, Months, and Days Between Two Dates


To calculate the number of years, months, and days between two dates, and not display the year if it is less than one year, simply subtracting is not enough. Such calculations need to follow a specific formula.

Formula
The formula is:

=TEXT(DATEDIF(A2,B2,”y”),”#年;;;”)&TEXT(DATEDIF(A2,B2,”ym”),”#月;;;”)&TEXT(DATEDIF(A2,B2,”md”),”#天;;;”)

Formula Explanation

  • DATEDIF(A2,B2,”y”): Finds out how many whole years are between A2 and B2. For example, from May 16, 2019, to June 25, 2019, it is 0 years.
  • TEXT(DATEDIF(A2,B2,”y”),”#年;;;”): Displays the whole year number obtained from DATEDIF(A2,B2,”y”) in the format “#年;;;”.

The format here is separated by three semicolons, representing four different formats for the following four values:

  1. Positive format
  2. Negative format
  3. Zero value format
  4. Text format

“#年;;;” means that when the content is a positive number, it will be displayed in the “#年” format; when it is negative, zero, or text, it will be displayed as blank. Since the differences will only yield positive or zero values, if there is more than one whole year, it will be displayed in the “#年” format, or nothing will be shown.

  • DATEDIF(A2,B2,”ym”): Determines how many whole months (ignoring years) are between A2 and B2. For example, from May 16, 2019, to June 25, 2019, it is 1 month. From February 3, 2011, to November 14, 2012, it is 9 months, not 21 months.
  • TEXT(DATEDIF(A2,B2,”ym”),”#月;;;”): Works the same as the previous TEXT(DATEDIF(A2,B2,”y”),”#年;;;”).
  • TEXT(DATEDIF(A2,B2,”md”),”#天;;;”): Functions similarly to TEXT(DATEDIF(A2,B2,”y”),”#年;;;”).

全面的技術支援解決方案

我們提供一系列技術支援解決方案,以滿足您的需求。
讓我們來探索我們的主要服務:

man and woman wearing headphones while working in the office

這是您隨時可以獲得的服務,專注於Microsoft Excel、Word和PowerPoint的即時協助。如果您在工作中遇到困難,只需通過WhatsApp發送您的問題給我們。我們將迅速幫助您解決問題!

serious diverse students looking at laptop

加入我們的「網上學習群組」Facebook頁面!我們提供超過200個教程,擁有豐富的教學視頻庫。您可以隨時隨地按照自己的步調學習,探索各種主題!

woman in yellow blazer doing a presentation

通過我們量身定制的企業培訓計劃提升您團隊的技能。我們提供全面的培訓課程,旨在滿足您組織的需求,為員工提供最新的工具,以助其卓越表現。