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 />

Determining whether a year is a leap year<br />

To determine whether a particular year is a leap year, you can write a formula that determines whether the<br />

29th day of February occurs in February or March. You can take advantage of the fact that Excel’s DATE<br />

function adjusts the result when you supply an invalid argument — for example, a day of 29 when February<br />

contains only 28 days.<br />

The following formula returns TRUE if the year of the date in cell A1 is a leap year. Otherwise, it returns<br />

FALSE.<br />

CAUTION<br />

=IF(MONTH(DATE(YEAR(A1),2,29))=2,TRUE,FALSE)<br />

This function returns the wrong result (TRUE) if the year is 1900. See “Excel’s leap year bug,”<br />

earlier in this chapter.<br />

Determining a date’s quarter<br />

For financial reports, you may find it useful to present information in terms of quarters. The following formula<br />

returns an integer between 1 and 4 that corresponds to the calendar quarter for the date in cell A1:<br />

=ROUNDUP(MONTH(A1)/3,0)<br />

This formula divides the month number by 3 and then rounds up the result.<br />

Time-Related Functions<br />

Excel also includes a number of functions that enable you to work with time values in your formulas. This<br />

section contains examples that demonstrate the use of these functions.<br />

Table 13.5 summarizes the time-related functions available in Excel. When you use the Insert Function dialog<br />

box, these functions appear in the Date & Time function category.<br />

TABLE 13.5<br />

Time-Related Functions<br />

Function<br />

HOUR<br />

MINUTE<br />

MONTH<br />

NOW<br />

SECOND<br />

TIME<br />

TIMEVALUE<br />

Description<br />

Converts a serial number to an hour<br />

Converts a serial number to a minute<br />

Converts a serial number to a month<br />

Returns the serial number of the current date and time<br />

Converts a serial number to a second<br />

Returns the serial number of a particular time<br />

Converts a time in the form of text to a serial number<br />

241

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

Saved successfully!

Ooh no, something went wrong!