Home » Time » How to calculate difference between two dates and times in excel?

How to calculate the time difference between two dates and times in excel?

If you need to calculate the time difference between two dates and times in Excel, including the differences in years, months, days, hours, minutes, and seconds, follow the step-by-step guide below.

Related

Age Calculator | Date Calculator | Time Calculator

Given:

  • Start Time (A2): 2020-05-15 08:00:00
  • End Time (B2): 2025-02-20 14:30:00

Step-by-Step Guide:

1. Enter Data in A2 and B2 Cells:

First, enter the two timestamps into Excel:

  • A2 (Start Time): 2020-05-15 08:00:00
  • B2 (End Time): 2025-02-20 14:30:00

2. Calculate the Difference in Years:

Formula:

Method 1: Using DATEDIF (Whole Years Difference)

If you only want to calculate the number of complete years (without decimals), use DATEDIF:

In cell D2, enter the following formula:

=DATEDIF(A2, B2, "y")

Result:  4

Explanation:
The difference in years between 2020-05-15 and 2025-02-20 is 4 full years.

Method 2: Using YEARFRAC (Precise Year Difference with Decimals)

If you want to calculate the precise number of years (including decimals), use YEARFRAC:

In cell D3, enter the following formula:

=YEARFRAC(A2, B2)

Result: 4.76

Explanation:

  • The decimal part represents the fraction of a year.
  • 0.76 of a year is approximately 9 months (since 0.76 × 12 months ≈ 9 months).
  • Therefore, 4.76 years means 4 full years and about 9 additional months.
  • which is 4 years and 9 months.

 


 

3.How to Calculate the Time Difference in Months in Excel

If you want to express the difference between two dates (A2 and B2) in months, you can use the following methods:

Method 1: Using DATEDIF (Whole Months Difference)

If you only want to calculate the number of complete months (ignoring days):

Formula:
In cell D4, enter the following formula:

=DATEDIF(A2, B2, "ym")

Result: 57.00

Explanation:
The difference in months between 2020-05-15 and 2025-02-20 is a total of 57 full months.

Method 2: Using YEARFRAC (Precise Month Difference with Decimals)

If you want a more precise month difference, including decimals, you can use YEARFRAC multiplied by 12:

In cell D5, enter the following formula:

=YEARFRAC(A2, B2) * 12

Result: 57.12 (meaning 57 months plus a few extra days)

Explanation of 57.12:

  • 0.12 represents about 12% of a year, which is approximately 4 days (since 0.12 × 30 ≈ 4).
  • So 57.12 months ≈ 57 full months and 4 extra days.

Method 3: Using DATEDIF to Get Both Years and Months

If you want the result in a format like “4 years 9 months”, use this formula:

=DATEDIF(A2, B2, “y”) & ” years ” & DATEDIF(A2, B2, “ym”) & ” months”

Result: 4 years 9 months

 


 

4.How to Calculate the Difference in Days in Excel?

If you want to express the difference between two dates (A2 and B2) in days, you can use the following methods:

Method 1: Direct Date Subtraction

In Excel, you can simply subtract the dates to get the difference in days:

=B2 – A2

Result: 1742.27 (meaning 1742 days between the two dates)

Method 2: Using DATEDIF for Day Difference

You can also use the DATEDIF function to calculate the difference in days:

=DATEDIF(A2, B2, “d”)

Result: 1742.00 (meaning 1742 days)

 


 

5. How to Calculate the Time Difference in Years, Months, and Days in Excel?

If you want to express the difference between two dates (A2 and B2) in years, months, and days, you can use the following methods:

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

  • Result: 4 years 9 months 5 days

Explanation:

  • DATEDIF(A2, B2, "y") calculates the full years difference.
  • DATEDIF(A2, B2, "ym") calculates the remaining months after removing the years.
  • DATEDIF(A2, B2, "md") calculates the remaining days after removing the years and months.

 


 

6. How to Calculate the Time Difference in Years, Months, Days, hours, minutes and seconds in Excel?

If you want to express the difference between two dates (2020/5/15 8:00:00 and 2025/2/20 14:30:00) in years, months, and days, hours, minutes and seconds, you can use the following methods:

use this formula:

=DATEDIF(A2, B2, “y”) & ” years ” &
DATEDIF(A2, B2, “ym”) & ” months ” &
DATEDIF(A2, B2, “md”) & ” days ” &
TEXT(B2 – A2, “h”) & ” hours ” &
TEXT(B2 – A2, “m”) & ” minutes ” &
TEXT(B2 – A2, “s”) & ” seconds”

Result: 

4 years 9 months 5 days 6 hours 10 minutes 0 seconds

Explanation:
This formula combines the differences in years, months, days, hours, minutes, and seconds into a single string, showing the full time difference is 4 years 9 months 5 days 6 hours 10 minutes 0 seconds.

Summary:

  1. Start Time: 2020-5-15 8:00:00
  2. End Time: 2025-2-20 14:30:00
  3. The calculated differences:
    • Years: 4 year
    • Months: 9 months
    • Days: 5 days
    • Hours: 6 hours
    • Minutes: 10 minutes
    • Seconds: 0 seconds
  4. Complete Time Difference: 4 years 9 months 5 days 6 hours 10 minutes 0 seconds. seconds
 
Related

Age Calculator | Date Calculator | Time Calculator

滚动至顶部