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.

Working with Dates and Times 13<br />

The advantage of using formulas (instead of the AutoFill feature) to create a series of dates is that you can<br />

change the first date, and the others update automatically. You need to enter the starting date into a cell and<br />

then use formulas (copied down the column) to generate the additional dates.<br />

The following examples assume that you entered the first date of the series into cell A1 and the formula into<br />

cell A2. You can then copy this formula down the column as many times as needed.<br />

To generate a series of dates separated by seven days, use this formula:<br />

=A1+7<br />

To generate a series of dates separated by one month, use this formula:<br />

=DATE(YEAR(A1),MONTH(A1)+1,DAY(A1))<br />

To generate a series of dates separated by one year, use this formula:<br />

=DATE(YEAR(A1)+1,MONTH(A1),DAY(A1))<br />

To generate a series of week days only (no Saturdays or Sundays), use the formula that follows. This formula<br />

assumes that the date in cell A1 is not a weekend day.<br />

=IF(WEEKDAY(A1)=6,A1+3,A1+1)<br />

Converting a nondate string to a date<br />

You may import data that contains dates coded as text strings. For example, the following text represents<br />

August 21, 2007 (a four-digit year followed by a two-digit month, followed by a two-digit day):<br />

20070821<br />

To convert this string to an actual date, you can use a formula, such as this one. (It assumes that the coded<br />

data is in cell A1.)<br />

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))<br />

This formula uses text functions (LEFT, MID, and RIGHT) to extract the digits, and then it uses these<br />

extracted digits as arguments for the DATE function.<br />

CROSS-REF<br />

Refer to Chapter 12 for more information about using formulas to manipulate text.<br />

Calculating the number of days between two dates<br />

A common type of date calculation determines the number of days between two dates. For example, you<br />

may have a financial worksheet that calculates interest earned on a deposit account. The interest earned<br />

depends on the number of days the account is open. If your sheet contains the open date and the close date<br />

for the account, you can calculate the number of days the account was open.<br />

Because dates are stored as consecutive serial numbers, you can use simple subtraction to calculate the<br />

number of days between two dates. For example, if cells A1 and B1 both contain a date, the following formula<br />

returns the number of days between these dates:<br />

=A1-B1<br />

233

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

Saved successfully!

Ooh no, something went wrong!