Milliseconds (1 Viewer)

rangersedge

Registered User.
Local time
Today, 15:47
Joined
Jun 13, 2014
Messages
82
I have a VBA code to import info. The problem is it imports the times as milliseconds. I can't seem to find the formula or code to convert this into minutes and seconds and the math work out correctly. It's either a little off or goes from 5 minutes to 52 hours... any help on converting this?
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:47
Joined
Jan 23, 2006
Messages
15,383
1 Hr = 60 Min
1 Min = 60 Sec
1 Sec = 1000 milliseconds
 

rangersedge

Registered User.
Local time
Today, 15:47
Joined
Jun 13, 2014
Messages
82
I know how the numbers work. I just can't get the query to spit out the correct answers.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:47
Joined
Sep 12, 2006
Messages
15,660
this any good. it drops the milliseconds, and formats the rest as hours:minutes: seconds. It's good for a few days, but 2bn ms doesn't equate to very many days!

Code:
 Function ms_to_time(ms As Long) As String
Dim secs As Long
Dim mins As Long
Dim hours As Long
Dim days As Long
Dim t As Date
 secs = ms / 1000
mins = secs / 60
secs = secs Mod 60
 hours = mins / 60
mins = mins Mod 60
  
 ms_to_time = TimeSerial(hours, mins, secs)
 End Function

? ms_to_time(340123)
 

rangersedge

Registered User.
Local time
Today, 15:47
Joined
Jun 13, 2014
Messages
82
I'm trying to use a query. Something like 433093 should return 7:13
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:47
Joined
Jan 23, 2006
Messages
15,383
433093 millisecs = 433.093 sec
433.093 sec = 7.21 min
.21 min = .21*60 =12.6 sec
so 433093 millisecs = 7 min 12.6 sec
 

pr2-eugin

Super Moderator
Local time
Today, 21:47
Joined
Nov 30, 2011
Messages
8,494
I'm trying to use a query. Something like 433093 should return 7:13
I think that is what Dave gave you there. Copy the function he has given you into a Standard module. Compile the code, so your compiler understands it. Then in a Query use something like.
Code:
SELECT secondsFieldName, ms_to_time(secondsFieldName) As properTime
FROM yourTableName;
 

Users who are viewing this thread

Top Bottom