How to use the TIMEVALUE function
What is the TIMEVALUE function?
The TIMEVALUE function returns a decimal number representing an Excel time value, based on a text string. Excel uses decimal numbers between 0 and 0.99988426 formatted as time. 0 (zero) is 12:00:00 AM and 0.99988426 is 11:59:59 P.M.
The TIMEVALUE function in Excel is rarely needed to convert values in formulas. Excel automatically handles conversion of numbers, text, logical values, and error values as required. TIMEVALUE function is provided for compatibility with other spreadsheet applications. In most cases, Excel will format values correctly without requiring the TIMEVALUE function function.
Only use TIMEVALUE function if you find Excel is not properly converting a value to text in a specific formula. In general, you can avoid using it entirely since Excel auto-converts types seamlessly in most situations.
Table of Contents
1. Introduction
What is an Excel time value?
Excel time is actually a decimal number ranging between 0 and 1 in Excel and then formatted as time.
For example, 12:00 PM is represented as 0.5 because it is half of a day, you can verify this by typing 12:00 PM in a cell and then change the cell formatting to general. This will show the value as Excel interprets it.
Does the TIMEVALUE function ignore dates?
Yes, the TIMEVALUE function ignores the date part , example "22-Aug-2019 6:35 PM" returns 0.774305556 which is equal to "6:35 PM".
How does Excel recognize time values?
Excel recognizes certain text strings like "6:45 PM" as valid time values. A recognized time value is right aligned in the cell just like a regular number, shown in the image below in cell B2.
A time number that is not recognized is left aligned which is demonstrated in cell B4 in the image above. This visual feedback lets you easily spot values that need closer inspection.
How to show the decimal value as an Excel time value?
- Select the cell containing the decimal value.
- Press CTRL + 1 to open the "Format Cells" dialog box shown in the image above.
- Select category "Time".
- Select a type.
- Press with left mouse button on the "OK" button.
Why convert time values to decimal numbers?
The conversion allows you to perform arithmetic operations to time values, this works only if the time value is represented as a numerical value.
This lets you add or subtract, for instance, hours, minutes, and seconds easily using simple Excel formulas. It also lets you perform average, median, and other calculations using specific Excel functions.
2. Syntax
TIMEVALUE(time_text)
time_text | Required. A text string within quotation marks that represent time, for example "03:23 PM" or "22:21". |
3. Example 1
The image above demonstrates the TIMEVALUE function in cells B3 to B8, column C describes the formula in grey text.
The first value demonstrated in cell B3 is 0.075, which is the result of TIMEVALUE("1:48 AM"). The TIMEVALUE function converts the time string "1:48 AM" to a decimal number representing the fraction of a 24-hour day. 1:48 AM is 1.8 hours after midnight, which is 1.8/24 = 0.075 of a day.
Formula in cell B3:
The second value demonstrated in cell B4 is 0.757638889, which is the result of TIMEVALUE("6:11 PM"). The TIMEVALUE function converts the time string "6:11 PM" to a decimal number. 6:11 PM is 18.183333 hours after midnight, which is 18.183333/24 ≈ 0.757638889 of a day.
The third value demonstrated in cell B5 is 0.415277778, which is the result of TIMEVALUE("9:58 AM"). The TIMEVALUE function converts the time string "9:58 AM" to a decimal number. 9:58 AM is 9.966667 hours after midnight, which is 9.966667/24 ≈ 0.415277778 of a day.
The fourth value demonstrated in cell B6 is 0.999988426, which is the result of TIMEVALUE("11:59:59 PM"). The TIMEVALUE function converts the time string "11:59:59 PM" to a decimal number. 11:59:59 PM is 23.99972 hours after midnight, which is 23.99972/24 ≈ 0.999988426 of a day.
The fifth value demonstrated in cell B7 is 0, which is the result of TIMEVALUE("0:00 AM"). The TIMEVALUE function converts the time string "0:00 AM" (midnight) to a decimal number. Midnight represents the start of the day, so it's 0/24 = 0 of a day.
The sixth value demonstrated in cell B8 is 0.5, which is the result of TIMEVALUE("12:00 PM"). The TIMEVALUE function converts the time string "12:00 PM" (noon) to a decimal number. Noon is exactly halfway through the day, so it's 12/24 = 0.5 of a day.
The decimal numbers shown in cells B3 to B8 are the actual Excel time representation of:
- 1:48 AM
- 6:11 PM
- 9:58 AM
- 11:59:59 PM
- 0:00 AM
- 12:00 PM
4. Example 2
This example demonstrates the FILTER and TEXTSPLIT functions work together to extract the time from the text, and then TIMEVALUE converts it to a decimal fraction that represents a time value in Excel.
Formula in cell D3:
The first value demonstrated in cell D3 is 0.458333333, which is the result of extracting and converting "11:00 PM" from the text in B3. The TIMEVALUE function converts this time to a decimal representing the fraction of a day. 11:00 PM is 23 hours after midnight, which is 23/24 ≈ 0.458333333 of a day.
The second value demonstrated in cell D4 is 0.102083333, which is the result of extracting and converting "2:27 PM" from the text in B4. The TIMEVALUE function converts this time to a decimal. 2:27 PM is 14.45 hours after midnight, which is 14.45/24 ≈ 0.102083333 of a day.
The third value demonstrated in cell D5 is 0.290277778, which is the result of extracting and converting "6:58 AM" from the text in B5. The TIMEVALUE function converts this time to a decimal. 6:58 AM is 6.966667 hours after midnight, which is 6.966667/24 ≈ 0.290277778 of a day.
The fourth value demonstrated in cell D6 is 0.538194444, which is the result of extracting and converting "12:55 PM" from the text in B6. The TIMEVALUE function converts this time to a decimal. 12:55 PM is 12.916667 hours after midnight, which is 12.916667/24 ≈ 0.538194444 of a day.
The fifth value demonstrated in cell D7 is 0.415277778, which is the result of extracting and converting "9:58 AM" from the text in B7. The TIMEVALUE function converts this time to a decimal. 9:58 AM is 9.966667 hours after midnight, which is 9.966667/24 ≈ 0.415277778 of a day.
Here is an explanation of the formula step by step:
- TEXTSPLIT(B3, " "): This function splits the contents of cell B3 into an array, using the space character (" ") as the delimiter.
The result of this function is an array of mostly text values and one time value. - TIMEVALUE(TEXTSPLIT(B3, " ")): This part of the formula applies the TIMEVALUE function to each element of the array created by TEXTSPLIT.
The TIMEVALUE function converts the time portion of the cell's contents into a valid time value. If the element is not a valid time, the TIMEVALUE function will return an error. - ISNUMBER(TIMEVALUE(TEXTSPLIT(B3, " "))): This part of the formula checks if the TIMEVALUE function was able to successfully convert the time portion of the cell's contents into a valid time value.
The ISNUMBER function returns TRUE if the result of TIMEVALUE is a valid number (i.e., a time value), and FALSE otherwise. - FILTER(TIMEVALUE(TEXTSPLIT(B3, " ")), ISNUMBER(TIMEVALUE(TEXTSPLIT(B3, " ")))): The FILTER function takes two arguments: the array of time values (from the TIMEVALUE function) and the array of boolean values (from the ISNUMBER function).
The FILTER function then returns only the time values that correspond to the TRUE values in the second argument, effectively filtering out any invalid time values.
5. Function not working
The TIMEVALUE function returns
- #VALUE! error if you use an invalid function.
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
5.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
5.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The TIMEVALUE function requires valid values which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
5.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
'TIMEVALUE' function examples
The following article has a formula that contains the TIMEVALUE function.
Functions in 'Date and Time' category
The TIMEVALUE function function is one of 22 functions in the 'Date and Time' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form