Saturday, February 22, 2020

DATEDIF Function in Excel with Example


DATEDIF ()

This function calculates the difference between two dates. It can show the result in weeks, months or years.

 Best view in desktop mode.


A
B
C
D
E
F
1
First Date
Second Date
Interval
Difference


2
2-Oct-15
22-Feb-20
Total Days
1604
=DATEDIF(A2,B2,"D")
3
2-Oct-15
22-Feb-20
Total Months
52
=DATEDIF(A3,B3,"M")
4
2-Oct-15
22-Feb-20
Total Years
4
=DATEDIF(A4,B4,"Y")
5
2-Oct-15
22-Feb-20
Days in Year
143
=DATEDIF(A5,B5,"YD")
6
2-Oct-15
22-Feb-20
Months in Year
4
=DATEDIF(A6,B6,"YM")
7
2-Oct-15
22-Feb-20
Days in Month
20
=DATEDIF(A7,B7,"MD")
8








Syntax

=DATEDIF (First Date, Second Date, "Interval")

First Date       : This is the earliest of the two dates. Old Date
Second Date  : This is the most recent of the two dates. New Date
"Interval"       : This indicates what you want to calculate. Difference Type

These are the available intervals:
"D" or "d"                  Days between the two dates.
"M" or "m"                Months between the two dates.
"Y" or "y"                   Years between the two dates.
"YD" or "yd"              Days between the dates, in the same year.
"YM" or "ym"            Months between the dates, in the same year.
"MD" or "md"           Days between the two dates, same month and year.




Formatting

No special formatting is needed.



Example

To calculate age in years, months and days below is the example.

A
B
C
D
1
Enter DOB :
12-Aug-92


2




3
Years lived :
27
=DATEDIF(B1,TODAY(),"y")
4
and Months :
6
=DATEDIF(B1,TODAY(),"ym")
5
and Days :
10
=DATEDIF(B1,TODAY(),"md")
6




7
Your Age is 27 Years, 6 Months and 10 Days


Formula in cell A7

="Your Age is "&DATEDIF(B1,TODAY(),"Y")&" Years, "&DATEDIF(B1,TODAY(),"YM")&" Months and "&DATEDIF(B1,TODAY(),"MD")&" Days"





                       




No comments:

Post a Comment