The HOUR, MINUTE and SECOND functions are designed to take an Excel serial date/time number and convert it to an hour, minute or second number representation. Of great use when building dashboards or worksheet tables that will be used in Pivot Tables.
The Excel HOUR, MINUTE and SECOND functions are computer programs that you run from a worksheet cell formula. They convert an Excel serial date number like 42005.5 in to an hour number range from 0-23, a minute number range from 0-59 and a second format like 0-59. You run these functions by typing their names in a formula then followed by the information they are suppose to use. These worksheet functions are used when you have to tear a date/time apart by its hour, minute and second number components. Their components are then used for tasks like logic, lookups, mathematical operations like + and -, and table construction so the tables can be filtered with Excel's data tools like Pivot Tables, Sort and Autofilter.
Whenever you type a formula in a worksheet cell, this is called syntax or grammar. The general function syntax for these functions has a format like these when you type them in a worksheet cell:
= HOUR( serial_number )
= MINUTE( serial_number )
= SECOND( serial_number )
Where serial_number is called the function argument list. Remember, you are running a computer program at this point so the program needs information to operate and that is why there is an argument list. When you see an argument list and you see square brackets [ ] around the argument name, this means the argument is optional and you do not have to include it when typing unless you need it. So for the syntax above, you need to include 1 argument when typing the functions in a worksheet cell formula in order for it to calculate correctly. What argument values can be used are discussed below. Remember functions expect certain things in their argument lists, if you do not put the correct information in the list they will generate an error when run.
Since the HOUR, MINUTE and SECOND functions are computer programs, they run when you press Enter to enter the formula that contains them. If any of their arguments are wrong, the functions will return an error.
When typing the HOUR, MINUTE and SECOND functions in a worksheet cell formula, you need to replace the serial_number argument with something that generates the serial number needed. Some typical arguments you can use are:
Argument Type | Cell Formula | Example Explanation |
Cell Reference | = HOUR( A1 ) | Returns the hour number based upon what serial date/time number is in cell A1. For example if 8/24/2015 6:00:00 AM was in cell A1 then 6 would be returned |
Range Reference | = MINUTE( A1:A10 ) | Returns an array of minute numbers based upon the dates in cells A1 to A10 |
Nested Functions | = SECOND( TIMEVALUE( "8:24:59 AM" ) ) | Returns a second number based upon the decimal value returned from the TIMEVALUE function. Very common argument type for dashboard problems and from data stored in multiple columns |
The worksheet seen below contains some typical worksheet formulas that run the HOUR worksheet function. Pay close attention to the argument list and the syntax used to write the formula.
A | B | C | |
1 | Time | ||
2 | 1/1/2015 8:05:59 AM | ||
3 | |||
4 | Formula below uses the HOUR function to obtain the hour from the date/time above, then VLOOKUP uses it to lookup an hour in another table. Typical use in a VLOOKUP formula | ||
5 | = VLOOKUP( HOUR( A2 ), $G$1:$K$100, 3, FALSE ) |
Excel Training Services
Microsoft Excel Products
EMAGENIT Company Information
Copyright © 2002-2019
EMAGENIT All Rights Reserved