Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Converting Numeric Values to Times.

# Converting Numeric Values to Times

by Allen Wyatt
(last updated October 27, 2020)

Sam has a lot of worksheets that contain times. The problem is that the times are in the format "1300" instead of the format "13:00." Thus, Excel sees them as regular numeric values instead of recognizing them as times. Sam wants them to be converted to actual time values.

There are several ways you can approach this task. One way is to use the TIME function to convert the value to a time, as shown here:

```=TIME(LEFT(A1,2),RIGHT(A1,2),)
```

This formula assumes that the time in cell A1 will always contain four digits. If it does not (for instance, it might be 427 instead of 0427), then the formula needs to be modified slightly:

```=TIME(LEFT(A1,LEN(A1)-2),RIGHT(A1,2),)
```

The formula basically pulls the leftmost digit (or digits) and uses them for the hours argument of the TIME function, and then uses the two rightmost digits for the minutes argument. TIME returns an actual time value, formatted as such in the cell.

A similar formulaic approach can be taken using the TIMEVALUE function:

```=TIMEVALUE(REPLACE(A1,LEN(A1)-1,0,":"))
```

This formula uses REPLACE to insert a colon in the proper place, and then TIMEVALUE converts the result into a time value. You will need to format the resulting cell so that it displays the time as you want.

Another variation on the formulaic approach is to use the TEXT function, in this manner:

```=--TEXT(A1,"00\:00")
```

This returns an actual time value, which you will then need to format properly to be displayed as a time.

Another approach is to simply do the math on the original time to convert it to a time value used by Excel. This is easy once you realize that time values are nothing more than a fractional part of a day. Thus, a time value is a number between 0 and 1, derived by dividing the hours by 24 (the hours in a day) and the minutes by 1440 (the minutes in a day). Here is a formula that does that:

```=INT(A1/100)/24+MOD(A1,100)/1440
```

This determines the hour portion of the original value, which is then divided by 24. The minute portion (the part left over from the original value) is then divided by 1440 and added to the first part. You can then format the result as a time, and it works perfectly.

All of the formulas described so far utilize a new column in order to do the conversions. This is handy, but you may want to actually convert the value in-place, without the need for a formula. This is where a macro can come in handy. The following macro will convert whatever cells you have selected into time values and format the cells appropriately:

```Sub NumberToTime()
Dim rCell As Range
Dim iHours As Integer
Dim iMins As Integer

For Each rCell In Selection
If IsNumeric(rCell.Value) And Len(rCell.Value) > 0 Then
iHours = rCell.Value \ 100
iMins = rCell.Value Mod 100
rCell.Value = (iHours + iMins / 60) / 24
rCell.NumberFormat = "h:mm AM/PM"
End If
Next
End Sub
```

The macro uses an integer division to determine the number of hours (iHours) and stuffs the remainder into iMins. This is then adjusted into a time value and placed back into the cell, which is then formatted as a time. You can change the cell format, if desired, to any of the other time formats supported by Excel.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10101) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Converting Numeric Values to Times.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Determining Word Frequency

How to construct a word frequency list.

Discover More

Printing Personalized Copies of a Document

Need to have a series of documents customized for individual users? Mail merge may be overkill, but the macro presented ...

Discover More

Printing Copy Numbers

Copy 1, Copy 2, Copy 3... Do you want to mark your printouts so that they are numbered? Here's how you can do it.

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

##### More ExcelTips (ribbon)

Dealing with Midnight Ending a Day

Dealing with times in Excel is fairly straightforward, except when it comes to midnight. Some people prefer that midnight ...

Discover More

Working with Elapsed Time

Work with times in a worksheet and you will eventually want to start working with elapsed times. Here's an explanation of ...

Discover More

Determining If a Date and Time is within Working Hours

Excel is great at working with times and dates. Sometimes, though, it can be a bit tricky to figure out how to work with ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven more than 0?

2020-10-27 10:15:43

Michel Saulnier

You are amazing thank you for posting all these tips

2020-10-27 07:23:23

Willy Vanhaelen

With the macro in my previous comment you will have to pre-format your selection or do it after running the macro. This two line version will do it for you. Adjust the format code to your liking.

Sub NumberToTime2()
Selection.NumberFormat = "h:mm AM/PM"
End Sub

2020-10-27 06:35:01

Willy Vanhaelen

For people who are happy with the hh:mm format, this one liner macro will do the job:

Sub NumberToTime()
End Sub

2018-02-22 11:06:21

Peter Atherton

Willy Vanhaelen

Yes thanks Willy, I just never use that format and did not think ahead.

2018-02-22 06:49:50

Willy Vanhaelen

@Peter Atherton
Your formula only works if the civilian time is entered as text like 06:14. It doesn't work if in cell B3 you enter for instance 6:14 or 6:14 AM or 6:14 PM or 06:14 PM. It doesn't work at all with Excel time such as 9:14 which is in fact 0.26.

My formula posted 2017.04.23 work correctly in all circumstances.

2018-02-21 11:36:00

Peter Atherton

Dave Manuel

Another shorter way

=MID(B3,1,2)&MID(B3,4,2)

2018-02-20 03:26:18

Michael (Micky) Avidan

@Scott Johnson,
The REPLACE Formula should refere to cell A7 instead of A4.
(see Figure 1 below)
----------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL

Figure 1.

2018-02-20 03:22:33

Michael (Micky) Avidan

@Scott Johnson,
Try my suggestion in the following picture.
Cell D7 proves that it does not matter if the Time is presented as "Text".
(see Figure 1 below)
----------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL

Figure 1.

2018-02-19 11:29:36

Scott Johnson

i need to convert 144004 to time 14:40:04. What formula would allow me to do this?

2017-04-23 08:01:31

Willy Vanhaelen

@Dave Manuel
This schould do the job:
=TEXT(HOUR(A1),"00")&TEXT(MINUTE(A1),"00")

2017-04-22 06:58:15

Dave Manuel

Slick way to convert military time to civilian time. How about civilian time to military?

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.