Convert a time stored as number to time format

AdRock

Board Regular
Joined
Apr 1, 2011
Messages
128
I need to convert a time which is written as 851 to 8:51 but stored in a time format. At the moment it is stored in a general format.

What i want to do is subtract times so i can get a total number of minutes which i can do once all these times are stored in a time format.

Is there a way i can convert a number like that into hh:mm?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
=if(g7>2359,"unknown time",if(len(g7)=3,left(g7,1)&":"&right(g7,2),if(len(g7)=4,left(g7,2)&":"&right(g7,2),"unknown time")))
 
Upvote 0
Try this in a module:

Code:
Function TimeConvert(Target As Range) As Date

TimeConvert = TimeSerial(Left(Target.Value, Len(Target.Value) - 2), Right(Target.Value, 2), 0)

End Function
 
Upvote 0
Thanks for your suggestions

Arcticwarrio's solution worked fine. Saved me hours of work

Many thanks guys
 
Upvote 0
One last question.

It works spot on but is there a way i can have a leading zero for hours between midnight and 9am so my time would look like 09:56 instead of 9:56?

Many thanks
 
Upvote 0
One last question.

It works spot on but is there a way i can have a leading zero for hours between midnight and 9am so my time would look like 09:56 instead of 9:56?

Many thanks

If you use my UDF function above, it will convert it to an Excel Time Serial so you can custom format it in Cell Formatting.
 
Upvote 0
Hit Alt+F11 to go into VBA.

Click Insert - Module and you will see "Module 1" appear in your Project window on the left

Double click Module1 to open it and paste my code above in.

Go back into Excel and you now have a custom function to use like any other function

in a cell type =TimeConvert(A1)
(where A1 is your time) and it will convert it to an excel time serial. Format the cell to hh:mm and hey presto!
 
Upvote 0
=IF(G7>2359,"unknown time",IF(LEN(G7)=3,"0"&LEFT(G7,1)&":"&RIGHT(G7,2),IF(LEN(G7)=4,LEFT(G7,2)&":"&RIGHT(G7,2),"unknown time")))
 
Upvote 0
This worked for 815:

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

Still need to format as time though.

If you actually want 8:15 then remove the --.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top