{"id":1525,"date":"2021-05-30T17:05:00","date_gmt":"2021-05-30T09:05:00","guid":{"rendered":"https:\/\/www.fyndpro.com\/?p=1525"},"modified":"2024-10-02T17:36:26","modified_gmt":"2024-10-02T09:36:26","slug":"calculate-the-years-months-and-days-between-two-dates","status":"publish","type":"post","link":"https:\/\/www.fyndpro.com\/en\/calculate-the-years-months-and-days-between-two-dates\/","title":{"rendered":"Calculate the Years, Months, and Days Between Two Dates"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1955\" src=\"https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=1024%2C576&#038;ssl=1\" alt=\"\" width=\"1024\" height=\"576\" srcset=\"https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=18%2C10&amp;ssl=1 18w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=1000%2C563&amp;ssl=1 1000w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=230%2C129&amp;ssl=1 230w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=350%2C197&amp;ssl=1 350w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?resize=480%2C270&amp;ssl=1 480w, https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/10\/17.jpg?w=1200&amp;ssl=1 1200w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/p>\n<p>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.<\/p>\n<p><strong>Formula<\/strong><br \/>\nThe formula is:<\/p>\n<div>\n<div>\n<div data-collapsed=\"unknown\">\n<p><strong><em>=TEXT(DATEDIF(A2,B2,\u201dy\u201d),\u201d#\u5e74;;;\u201d)&amp;TEXT(DATEDIF(A2,B2,\u201dym\u201d),\u201d#\u6708;;;\u201d)&amp;TEXT(DATEDIF(A2,B2,\u201dmd\u201d),\u201d#\u5929;;;\u201d) <\/em><\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>Formula Explanation<\/strong><\/p>\n<ul>\n<li><code>DATEDIF(A2,B2,\u201dy\u201d)<\/code>: 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.<\/li>\n<li><code>TEXT(DATEDIF(A2,B2,\u201dy\u201d),\u201d#\u5e74;;;\u201d)<\/code>: Displays the whole year number obtained from\u00a0<code>DATEDIF(A2,B2,\u201dy\u201d)<\/code>\u00a0in the format \u201c#\u5e74;;;\u201d.<\/li>\n<\/ul>\n<p>The format here is separated by three semicolons, representing four different formats for the following four values:<\/p>\n<ol>\n<li>Positive format<\/li>\n<li>Negative format<\/li>\n<li>Zero value format<\/li>\n<li>Text format<\/li>\n<\/ol>\n<p>\u201c#\u5e74;;;\u201d means that when the content is a positive number, it will be displayed in the \u201c#\u5e74\u201d 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 \u201c#\u5e74\u201d format, or nothing will be shown.<\/p>\n<ul>\n<li><code>DATEDIF(A2,B2,\u201dym\u201d)<\/code>: 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.<\/li>\n<li><code>TEXT(DATEDIF(A2,B2,\u201dym\u201d),\u201d#\u6708;;;\u201d)<\/code>: Works the same as the previous\u00a0<code>TEXT(DATEDIF(A2,B2,\u201dy\u201d),\u201d#\u5e74;;;\u201d)<\/code>.<\/li>\n<li><code>TEXT(DATEDIF(A2,B2,\u201dmd\u201d),\u201d#\u5929;;;\u201d)<\/code>: Functions similarly to\u00a0<code>TEXT(DATEDIF(A2,B2,\u201dy\u201d),\u201d#\u5e74;;;\u201d)<\/code>.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>To calculate the number of years, months, and days betw [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3120,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[49,8,7,20,18],"tags":[161,162],"class_list":["post-1525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-date","category-excel","category-excel-formulas","category-onlinesupport","category-text","tag-datedif","tag-text"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.fyndpro.com\/wp-content\/uploads\/2020\/03\/Excel-new10.png?fit=2102%2C679&ssl=1","_links":{"self":[{"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/posts\/1525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/comments?post=1525"}],"version-history":[{"count":7,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/posts\/1525\/revisions"}],"predecessor-version":[{"id":3128,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/posts\/1525\/revisions\/3128"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/media\/3120"}],"wp:attachment":[{"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/media?parent=1525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/categories?post=1525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fyndpro.com\/en\/wp-json\/wp\/v2\/tags?post=1525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}