18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Part II<br />

Working with Formulas and Functions<br />

Calculating a person’s age<br />

A person’s age indicates the number of full years that the person has been alive. The formula in the previous<br />

section (for calculating the number of years between two dates) won’t calculate this value correctly. You can<br />

use two other formulas, however, to calculate a person’s age.<br />

The following formula returns the age of the person whose date of birth you enter into cell A1. This formula<br />

uses the YEARFRAC function.<br />

NEW FEATURE<br />

=INT(YEARFRAC(TODAY(),A1,1))<br />

In versions prior to Excel 2007, the YEARFRAC function was available only when the Analysis<br />

ToolPak add-in was installed. The function is now part of Excel 2007.<br />

The following formula uses the DATEDIF function to calculate an age. (See the sidebar, “Where’s the DATE-<br />

DIF Function?”)<br />

=DATEDIF(A1,TODAY(),”Y”)<br />

Where’s the DATEDIF Function?<br />

One of Excel’s mysteries is the DATEDIF function. You may notice that this function does not appear in the<br />

drop-down function list for the Date & Time category, nor does it appear in the Insert Function dialog<br />

box. Therefore, when you use this function, you must always enter it manually.<br />

The DATEDIF function has its origins in Lotus 1-2-3, and apparently Excel provides it for compatibility purposes.<br />

For some reason, <strong>Microsoft</strong> wants to keep this function a secret. The function has been available since<br />

Excel 5, but Excel 2000 is the only version that ever documented it in its Help system.<br />

DATEDIF is a handy function that calculates the number of days, months, or years between two dates. The<br />

function takes three arguments: start_date, end_date, and a code that represents the time unit of interest. The<br />

following table displays valid codes for the third argument. (You must enclose the codes in quotation marks.)<br />

Unit Code<br />

“y”<br />

“m”<br />

“d”<br />

“md”<br />

“ym”<br />

“yd”<br />

Returns<br />

The number of complete years in the period.<br />

The number of complete months in the period.<br />

The number of days in the period.<br />

The difference between the days in start_date and end_date. The months and years<br />

of the dates are ignored.<br />

The difference between the months in start_date and end_date. The days and years<br />

of the dates are ignored.<br />

The difference between the days of start_date and end_date. The years of the dates<br />

are ignored.<br />

The start_date argument must be earlier than the end_date argument, or the function returns an error.<br />

236

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!