Difference between two cells data in Years, Months, Days, Hours, Minutes

tree5ppm

New Member
Joined
Nov 20, 2021
Messages
1
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
  2. MacOS
Hello fellows,
Thank you for great forum that helps most of the formula doubts.

in my case. A2 has 2019-03-10 14:30
A3 has 2021-11-21 05:00

I would like to get results in B4 like "986 days, 14 hours, 30 minutes"
in B5 "2 years, 8 months, 10 days, 14 hours, 30 minutes"
in B6 "32 months, 10 days, 14 hours, 30 minutes"

Kind Regards
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I have used datedif , and get 11 days , maybe because of the way datedif works and counts complete days
B4
=INT(A3-A2) &" Days " & HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B5
=DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B6
=DATEDIF(A2,A3,"M") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "

I'll need to look into and see what the day is in more detail and if just using a -1 would work - because its including the 1st day

Cell Formulas
RangeFormula
B4B4=INT(A3-A2) &" Days " & HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B5B5=DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B6B6=DATEDIF(A2,A3,"M") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "


Yes its counting the Days ignoring the hours
for example, using the -1 otherwise we get 1 day
Cell Formulas
RangeFormula
B4B4=INT(A3-A2) &" Days " & HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B5B5=DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-1 & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B6B6=DATEDIF(A2,A3,"M") & " Months " & DATEDIF(A2,A3,"MD") -1& " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
 
Upvote 0
I'll need to look into and see what the day is in more detail and if just using a -1 would work - because its including the 1st day
DATEDIF will not see the time portion of what is in the cells, you need to subtract 1 when the end time is earlier than the start time.
 
Upvote 0
then we need to test the TIME to see if less or greater
so for the 2nd formula - will this work for you
=IF(TIME(HOUR(A2),MINUTE(A2),SECOND(A2))<=TIME(HOUR(A3),MINUTE(A3),SECOND(A3)),DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes ",DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-1 & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes ")

=IF(TIME(HOUR(A2),MINUTE(A2),SECOND(A2))<=TIME(HOUR(A3),MINUTE(A3),SECOND(A3)) we are testing the time to see if greater or less than , so has a day elapsed ?
If A2 is less then or equals A3 in time - we dont need to subtract a day
,DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes ",
if A2 is greater than A3
DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-1 & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes ")
 
Upvote 0
Could do it a bit shorter. Borrowing your original 2nd formula as a starting block
Excel Formula:
=DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-(MOD(B2,1)<MOD(A2,1)) & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
 
Upvote 0
thanks for simplifying formula for OP - but i get a zero days when only 1 day apart
Cell Formulas
RangeFormula
E5E5=DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-(MOD(B2,1)<MOD(A2,1)) & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B4B4=INT(A3-A2) &" Days " & HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
B5B5=IF(TIME(HOUR(A2),MINUTE(A2),SECOND(A2))<=TIME(HOUR(A3),MINUTE(A3),SECOND(A3)),DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD") & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes ",DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-1 & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes ")
B6B6=DATEDIF(A2,A3,"M") & " Months " & DATEDIF(A2,A3,"MD") -1& " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
 
Upvote 0
Sorry, typo. I entered a wrong cell reference.
Excel Formula:
=DATEDIF(A2,A3,"Y") & " Years " & DATEDIF(A2,A3,"YM") & " Months " & DATEDIF(A2,A3,"MD")-(MOD(A3,1)<MOD(A2,1)) & " Days "& HOUR((A3-A2) ) & " Hours " & MINUTE((A3-A2) ) & " Minutes "
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top