Calculating the difference between 2 dates
Excel Tip #002
Calculating the difference between 2 dates
Calculating the difference between 2
dates is more frequent problem which most of us faced. Below is a solution for
the same.
We are going to use 2 Excel function
in this post - DATEDIF() and NOW(). Let us
consider the first problem, calculating the difference between 2 dates where we
will use the DATEDIF() function.
The syntax of the DATEDIF() function
is,
=DATEDIF(start_date,
end_date, unit)
The value fields, start_date & end_date takes
up the date. unit field is the time unit that we are
going to use - years (y), months (m) or days (d).
Consider 2 dates as an example in
mmddyyyy format: Our start_date being 7/15/1967 (July 15, 1967) and end_date
12/8/1990 (December 8, 1990). The start_date and end_date are defined in cell
B2 & B3 in my excel.
To calculate the # of years. To
denote the number of years, I have concatenated the text "years"
using & symbol.
# of years, Formula: =DATEDIF(B2,B3,"y")&" years"
Retrieving # of years between 2 dates |
To calculate the # of months.
# of years & months, Formula: =DATEDIF(B2,B3,"ym")&" months"
# of months, Formula: =DATEDIF(B2,B3,"m")&" months"
Retrieving # of months between 2 dates |
To calculate the # of days.
# of months & days, Formula: =DATEDIF(B2,B3,"md")&" days"
# of days, Formula: =DATEDIF(B2,B3,"d")&" days"
Retrieving # of days between 2 dates |
Below, all the above formula are combined into one formula to get the # of years, months & days.
Formula: =DATEDIF(B2,B3,"y")&"years " & DATEDIF(B2,B3,"ym")&" months" & DATEDIF(B2,B3,"md")&" days"
Retrieving
# of years, months & days between 2 dates |
ADDITIONAL TIP - AGE CALCULATION
We are going to use the same DATEDIF() function in conjunction with NOW() function. The NOW() returns the current system date and time.
This is also similar to the above problem of calculating the difference between 2 dates but in the start_date field we will use the person birth date and in end_date field, we will use NOW() function.
Let us consider a person was born on 9/4/1978 (September 4, 1978) and wants to calculate the age. This person birth date is in cell B2 in my excel.
Formula: =DATEDIF(B2,NOW(),"y")&"years " & DATEDIF(B2,NOW(),"ym")&" months" & DATEDIF(B2,NOW(),"md")&" days"
Calculating the age of a person |
Comments
Post a Comment