Welcome to Excel Magic Trick number 1,262. Hey, if you want to download those workbooks, Excel Magic Trick 1,260 to 1,262, and follow along, click on the link below the video. Hey, we've got a great video here. We have some time values when we want to see how to convert them to text as HHMM, and then over here we want to see the reverse. We downloaded some text time values and we need to convert them to actual time values.
Now, time over here is a number, so anytime you're going from a number to text and you know the formatting you want to use, that's the perfect job for the TEXT function. The value: hey, I'm going to click on that time value, which is a number, comma, and you have to know custom number formatting. Custom number formatting for time is pretty straightforward: h means hour and m means minute. So I simply put double quotes around my custom number format. Now I need a leading zero, so instead of putting a single h, I put two h's. Now instead of just 6, it'll show 06. Then m m, and that's it. h means hour, m means minute, double quote, close parenthesis, and there we have it. Control enter, and boom, it's converted from an actual time value to HHMM text. Double-click and send it down, and boom.
Now the reverse is a little trickier. That's TEXT value equals TEXT, and we're still going to use that. You think, well, wait a second, that's supposed to be a number, but it'll work. Comma, and we cannot put double quotes and then HHMM, because that HHMM depends on the fact that it's an actual proper time value, which is a decimal between zero and one representing the proportion of a 24-hour day. So we're going to have to get tricky here. We'll use the significant and insignificant digit holder, zero. Now I'm going to put two zeros, because I'm definitely going to want to see the leading zero. But wait a second, that's text and it doesn't have the colon. Well, in custom number formatting you can insert characters, and we could put it in double quotes and join it, but there's an awesome custom number formatting character: backslash. That says to custom number format, whatever character you type next, in our case a colon, please insert it. 0 0 and double quote, close parentheses. Now that is pretty amazing custom number formatting. It says two digits, then insert a colon, then the next two digits. Now this is a TEXT function, and when I Control-Enter, sure enough, that's exactly the text we need to convert.
Now we convert the text time number back to an official number. So we F2, and in any math operation, text numbers are converted back to numbers. I'm going to add zero, Control-Enter. There's the proportion of a 24-hour day, that's 6 hours 45 minutes divided by 24. To display it as a time number, I'm simply going to come up here and choose Time. Now I can double-click and send it down, and boom, we've gone from text values in HHMM to actual time values over here, and from time values over here to actual text. In either case, text with HHMM or text with 0000 and backslash colon, the TEXT function does its job.
All right, we'll see you next video.
