Welcome to My Blog - Yogananth

Calculating an age between two dates using the DATEDIF function in EXCEL

It is easy to determine the number of days between any two dates simply by subtracting one from the other, but it is extremely difficult to return a string that says something like '24 years, 6 months and 8 days'. The maths and logic involved in this apparently straightforward question are very complex. You may wish to try it using the MONTH() and DAY() functions, but make sure you thoroughly test your formula!
An Excel function called DATEDIF() will perform this calculation although it is not included within the Excel help files or the function wizard until Excel 2000. It does however exist in previous versions of Excel. It takes the following structure: =DATEDIF(Date1, Date2, OutputRequirement). The first two parameters are simple, although you must ensure that the second date is greater than the first. The OutputRequirement parameter is a character code (typed inside inverted commas) that specifies the type of value you wish to obtain.
CodeDescriptionExplanation
"d"DaysThe number of days between Date1 and Date2.
"m"MonthsThe number of complete months between Date1 and Date2.
"y"YearsThe number of complete years between Date1 and Date2.
"yd"Days excluding YearsThe number of days between Date1 and Date2, as if Date1 and Date2 were in the same year.
"ym"Months excluding YearsThe number of months between Date1 and Date2, as if Date1 and Date2 were in the same year.
"md"Days excluding Months and YearsThe number of days between Date1 and Date2, as if Date1 and Date2 were in the same month and the same year.

This function is ideally suited to calculating someones precise age on any particular date or the number of days until your next birthday. The first date can be your date of birth and the second date is either entered in another cell by the user, or automatically set to todays date with the NOW() function.
The diagram illustrates the difference between the different types of day count. The first formula (row 26) counts the total number of days between the 2 dates. The next formula counts the days which are the remainder after the whole years are deducted. The final formula returns the number days after both the whole years and the months have been deducted.
-ABCD
30First DateSecond Date
31Date as typed02/05/9706/06/07
32Date formatted02 May 9706 Jun 07
33Years10 [B33] =DATEDIF(B31, C31, "Y")
34Months1 [B34] =DATEDIF(B31, C31, "YM")
35Days4 [B35] =DATEDIF(B31, C31, "MD")


-A
38Your age is 10 years, 1 months and 4 days.
39[A38] ="Your age is " & TEXT(B33, "0") & " years, " &
TEXT(B34, "0") & " months and " & TEXT(B35, "0") & " days."





















-ABC
23First DateSecond Date
24Date as typed02/02/8406/06/07
25Date formatted02 Feb 8406 Jun 07
26DateDif using 'D' argument8525
27DateDif using 'YD' argument125
28DateDif using 'MD' argument4

No comments: