Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Text to a time format 2

Status
Not open for further replies.

akaivyleaf

Programmer
Nov 1, 2000
42
0
0
US
Hi all, I would like to convert a general number into a time format dynamically. Currently time is put in without colons separating the hours, minutes and seconds. It appears as such: 95904 I need the number to appear as 9:59:04 Is there an easy way of converting this text into a time format?
 
format(Left(TheInput, len(TheInput)-4) & ":" &
Left(Right(TheInput, 4) ,2) & ":" &
Right(TheInput, 2), "hh:nn:ss")

should return 09:59:04

where TheInput = 95904
 
If you are in excel, and the input value in A1 is number:
=TIMEVALUE(TEXT(A1,"00"":""00"":""00"))

combo
 
To do it with sheet formulae instead of a macro, put this formula in a cell and copy down:

=TIMEVALUE(LEFT(A1,LEN(A1)-4)&":"&LEFT(RIGHT(A1,4),2)&":"&RIGHT(A1,2))

This gives Excel time values as results. Format as "hh:mm:ss" afterwards.

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Thank you both for the excellent tip. They both worked and accomplished my goal. I appreciate it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top