Using Advanced Date and Time Functions Dates and times are really just numbers—sometimes you might see them called “serial numbers”
Using Advanced Date and Time Functions Dates and times are really just numbers—sometimes you might see them called “serial numbers”
or “serialized dates.” Any date in Excel evaluates to the number of days since December 31st, 1899 (actually, Excel will try to tell you that zero is “January 0, 1900”). Any time in Excel is the corresponding fraction of a day—noon is midday, which is 0.5. The time 6:00 a.m. equals 0.25, and 6:00 p.m. equals 0.75. This allows us to easily calculate the number of days between dates, the number of hours between times, or to add up times.
The following exercise runs through several functions that work with date and time values, includ- ing the TODAY function, which returns the current date, and the NOW function, which returns the current date and time. Other functions extract parts of date values, such as year, month, or day; and extract parts of time values like hour, minute, or second.
In the exercise, we’ll also calculate the number of days between two dates and then use functions to calculate the number of working days between two dates (not counting weekends). Then, we’ll use an alternate function that allows us to count working days if we don’t have standard weekends. For example, our “weekends” are Tuesdays and Wednesdays instead of Saturdays and Sundays. Finally, we’ll calculate net working days that exclude holidays.
Other steps in the exercise will show how to project dates forwards or backwards if we have the starting or ending date and the number of days. We’ll do a simple projection; then we’ll project forwards and backwards 100 working days and then 100 working days with a list of holidays.
70 Lesson 3
STEP BY STEP
Use Advanced Date and Time Functions
GET READY . LAUNCH Excel 2016 if it is not already open.
1. OPEN the
03 Dates.xlsx workbook file for this exercise.
2. SAVE the workbook as
03 Dates Solution.xlsx .
3. Enter the following formulas into the specified cells:
B6 = TODAY( ) B7 = NOW( ) - TODAY( ) B8 = NOW( )
4. In cell C3 enter the formula:
= YEAR(B3)
Use AutoFill to fill the formula in C3 down through C8 . AutoFill will also copy cell
C3’s formatting into C4:C8. Click the AutoFill Options button and select Fill Without
Formatting .
5. Repeat step 4, entering the following formulas into the specified cells and filling down through row 8, filling the cells without formatting.
D3 = MONTH(B3) E3 = DAY(B3) F3 = HOUR(B3) G3 = MINUTE(B3) H3 = SECOND(B3) I3 = WEEKDAY(B3)
Your worksheet should resemble Figure 3-7, with the exception of the dates and times in rows 6-8, which will reflect your current date and time.
Figure 3-7 Entering advanced date and
time functions
6. Enter the following formula in N3 :
= M3-L3
7. Enter the following formula in O3 :
= NETWORKDAYS(L3,M3)
8. Enter the following formula in O4 : = NETWORKDAYS.INTL(L3,M3,4)
9. Enter the following formula in O5 :
= NETWORKDAYS(L3,M3,tbl.Holidays[Holidays])
10. Enter the following formula in M8 :
= L8+N8
11. Enter the following formula in L9 :
= M9-N9
12. Enter the following formula in M10 :
= WORKDAY(L10,O10)
13. Enter the following formula in L11 :
= WORKDAY(M11,-O11)
Using Advanced Functions and Analyzing Data
14. Enter the following formula in M12 :
= WORKDAY(L12,O12,tbl.Holidays[Holidays])
15. You may have noticed that Excel used serial numbers in cells M10, L11, and M12 instead of dates. Remember, the numbers don’t change when we convert a cell to a date, only the formatting changes. Format cells M10, L11, and M12 using the d-mmm-yy format (see Figure 3-8).
Figure 3-8 More advanced date and
time functions
16. SAVE the workbook and CLOSE it. PAUSE . LEAVE Excel open to use in the next exercise.
Using Nested Functions Whenever you place a function inside another function you are nesting them. You can nest almost
any function inside almost any other function. In the following exercise, we will nest a couple of functions to extract and transform first names from a list of first and last names, and change them to proper case.
STEP BY STEP
Use Nested Functions
GET READY . LAUNCH Excel 2016 if it is not already open.
1. OPEN the
03 Nested Functions.xlsx workbook file for this exercise.
2. SAVE the workbook as
03 Nested Functions Solution.xlsx .
3. Enter the following formula into cell C4 and then double-click the fill handle.
=FIND(“ “,B4)
4. Enter the following formula into cell D4 and then double-click the fill handle.
=LEN(B4)
5. Enter the following formula into cell E4 and then double-click the fill handle.
=D4-C4
6. Enter the following formula into cell F4 and then double-click the fill handle.
=RIGHT(B4,E4)
72 Lesson 3
7. Enter the following formula into cell G4 and then double-click the fill handle.
=PROPER(F4)
8. Enter the following formula into cell H4 and then double-click the fill handle.
=PROPER(RIGHT(B4,LEN(B4)-FIND(“ “,B4)))
This nested version of the formula incorporates the formulas entered in previous steps (see Figure 3-9). It uses four different functions, three of which (RIGHT, LEN, and FIND) are nested.
Figure 3-9 Using nested functions
9. SAVE the workbook and CLOSE it. PAUSE . LEAVE Excel open to use in the next exercise.