Postsecondary Home Tech Support Contact Us Product Info Search
A Professional Approach Series Glencoe Online
The e-Zine Approach
  • eZine Approach
Printer-Friendly Version
E-mail this Article
Archives
  • PAS Home
Using Date and Time Functions in Excel 2002

Have you ever wondered how long it has been since the first day of 1900? Maybe you haven’t, but the designers of Microsoft Excel decided to base their time and date functions on this day. Trying to determine the date exactly 1000 days from today without a computer requires the use of several calendars and a lot of time. With the use of a spreadsheet program, such as Excel, the exact day can be displayed in moments. In this article, you will examine and use many of the date and time functions built into Excel.

When a date is entered into a worksheet cell, Excel immediately converts the date into a serial number. January 1, 1900 is serial number 1 and the serial number of the date entered is the number of days since January 1, 1900. In Figure 1, three dates entered into cells in column A have been copied into column B. The only difference is that the dates in column B appear in the General format rather than a Date format.

Figure 1

Regardless of the format of the date, the value in memory is the serial number. Using date and time functions and arithmetic operators you may find the difference between two dates, determine the day of the week three months from the current day, or find the number of workdays within a given range of dates, excluding Saturday, Sunday, and holidays. Date and time functions in Excel fall into several categories, each of which is explored in the following sections.

Just Give Me the Number
Type in a date, as in 1/18/2002, and Excel immediately converts it into a date serial number. But what if you have the month, day, and year in different cells? The Date function requires three arguments, the month, the day, and the year. You can type in the pieces of the date directly into the function, or use the cell addresses containing the components. Figure 2 illustrates both ways to use the Date function. Note that the order of the arguments is the year, followed by the month, and finally the day. If you enter the date directly into the function, each of the arguments must be enclosed within quotation marks.

Figure 2

The Datevalue function works in much the same way, except it only has one argument — the date you want to convert, enclosed within quotation marks, in the yyyy/mm/dd format. An example is DATEVALUE(“2001/11/14”).

Excel can also display the time with or without the date. As far as Excel is concerned, the time is no more than a fraction of a day. For instance, .5 days is 12 noon, .25 is 6 a.m., and so on. You can use the Time and Timevalue functions to display the time either by entering the time directly into the function or by referencing the time in cells. Figure 3 shows the Time functions, and the result in both the General and the Time format. The Timevalue function lets you enter the time as hours, minutes, seconds as in TIMEVALUE(“10:15:00”) for 10:15 a.m.

Figure 3

There are two special functions useful when you want your worksheet to display the current date and/or time whenever the worksheet is opened. The Today function displays the current day in the mm/dd/yyyy format. Although you must type in the parentheses after the function, you must not enter any arguments. Therefore, TODAY() will display 2/13/2002 on February 13, 2002, 12/9/2005 on December 9, 2005, and so on. The Now function does the same thing as the Today function, except the result is formatted to display the current time as well as the current date. Like the Today function, the Now function has no arguments, as in NOW().

Give Me a Piece of That
Sometimes you have to take a date serial number and convert it into a value that is more meaningful to people. For example, the Day function displays just the day of the month of a date, regardless of the format of the date. Likewise, the Month, Year, Hour, Minute, and Second functions extract a portion of the date or time. Figure 4 illustrates each of these functions.

Figure 4

When Will That Be?
The above functions are the “plain vanilla” functions essential to many worksheets. Using these functions, and others, you can display and calculate the difference between dates, add or subtract days from a given date, and so on. But there are a number of specialized functions that perform tasks that would otherwise require many calculations and logical operations. For instance, the Weekday function returns the day of the week in which the date in the argument falls, 1 being Sunday, 2 Monday, 3 Tuesday, and so on. Another function, Weeknum, tells you the number of the week that a date falls within.

Then there are a group of functions that use two dates in their arguments, especially handy in accounting applications. Days360 figures out the number of days between two dates, based on a 360-day calendar (12, 30-day months). Yearfrac determines the fraction of a year represented by the two dates in the argument. Figure 5 shows examples of these functions.

Figure 5

Accounting solutions may depend on determining the date a specified number of months away or the last day of that month. Edate uses two arguments — the start date and the number of months until the same day of another month. For example, the Edate of 2/7/2003 with a second argument of 2 would be 4/7/2003 — the same day two months away. If the second argument is a negative number, the answer is a date in the past. So, EDATE(B12,-3) would be a date three months before the date in cell B12.

Eomonth works just like Edate except it finds the last day of the month. Just as with Edate, the arguments are the start date and the number of months before or after the start date. Therefore, EOMONTH(C15,5) would return the date May 31, 2002 if the start date in C15 was any day in January 2002.

Finally, there are two date functions that can be very useful to accounting and human resource departments, among others — Workday and Networkdays. The Workday function finds the next workday from a specified date, excluding holidays. The function has three arguments — the start date, the number of days before or after the start date, and a range of cells containing holidays that should not be considered as work days. Networkdays calculates the number of work days between a start date and an end date, again excluding holidays. Check out the examples in Figure 6 to see these amazing functions in action.

Figure 6

Odds and Ends

  • If you see #NAME? in a cell containing one of these functions, it may be that the function has not been loaded. Click Tools, Add-ins, and check the box labeled Analysis ToolPak. You may be asked to install the feature from your Microsoft Office XP or Excel XP disc. Check Excel Help on the needed function for instructions on installing this add-in.


  • By default, January 1, 1900 is considered to be date serial number 1. Some systems, such as Apple Macs, start counting on January 2, 1904. You can change this setting using the Regional Options tab in your Windows Control Panel.


  • When only the last two digits of the year are entered, unexpected results can occur. By default, Windows 98, Windows 2000, and Windows XP consider 00 through 29 as 2000 through 2029 and digits 30 through 99 as 1930 through 1999. You can change these defaults using the Regional Settings or Options in the Control Panel.



Recent Articles
Signed, Sealed, and Delivered: Outlook’s Signature and vCard Features   January 2002
If there’s anything we hate in this postmodern age, it’s anonymity. That’s why we appreciate personal touches that connect us to other people. You can use this to your advantage when you create e-mail messages.


Microsoft Office Round Trips   January 2002
Microsoft Office applications can export complicated documents to HTML and bring them back into the application that created them. They can do this without loss of data or formatting. Learn about specific problems that can be solved partly or completely through round tripping.


Time for Magic: User Assistance and Wizards   January 2002
Software grows more complex as users demand that it do more and more work for them. It’s ironic that this also means users can easily fail to obtain the result they intended. User Assistance and Wizards are here to help you.


Turning the (HTML) Tables: Importing Data from the Web Into Microsoft Excel   January 2002
Lots of information on the Web appears in the form of tables. These tables may contain text or numbers, or both. If you happen to need this information in a document you are creating, you can import it into a Microsoft Excel spreadsheet very quickly.


 
Glencoe/McGraw-Hill A Division of The McGraw-Hill Companies
 
©2001 The McGraw-Hill Companies, Inc. All rights reserved.