Time Conversion - Urgent

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a report that I download from applications, that show users and time
stat but the time are downloaded in seconds. Example

User Time1 Time2 Time3 Time4
Joe 203 57 11751
3443

I need a function that will covert these into usuable time format. Example
Need output for Joe to be as follow

Joe 3:23 0:57 3:15:51
0:57:23

I also need the ability to add these add and produce a time product such as
3:23 + :57 = 4:20

Will be forever grateful
thanks
Cip
 
Time in seconds is very useful. To get a displayed value, divide the seconds
value by 86400 which is the number of seconds in a day.

You should consider normalizing your table so that you can use a totals
query to sum across records rather than across fields.
 
Try using the Format function in your code. i.e. MyControl = Format(203,
"hh:mm:ss")

Use the actual value or a reference to the control that has the value.
 
Cip said:
I have a report that I download from applications, that show users and time
stat but the time are downloaded in seconds. Example

User Time1 Time2 Time3 Time4
Joe 203 57 11751
3443

I need a function that will covert these into usuable time format. Example
Need output for Joe to be as follow

Joe 3:23 0:57 3:15:51
0:57:23

I also need the ability to add these add and produce a time product such as
3:23 + :57 = 4:20


You can add the seconds the same way you would any other
numbers, so your question boils down to formatting a number
of seconds to hours, minutes and seconds.

This is probably best done by creating a function in a
standard module:

Const SecPerDay As Long = 24& * 60& * 60&

Public Function CvSeconds(sec As Long) As String
If sec \ 3600 = 0 Then
CvSeconds = Format(sec / SecPerDay, "n:ss")
Else
CvSeconds = sec \ 3600 & ":" & Format((sec Mod 3600) /
SecPerDay, "nn:ss")
End If
End Function
 
To format seconds as hours:minutes:seconds

[SecondsField] \ 3600 & Format(([SecondsField] Mod 3600) / 86400, ":nn:ss")

To format seconds as days:hours:minutes:seconds

[SecondsField] \ 86400 & Format(([SecondsField] Mod 86400) / 86400,
":hh:nn:ss")

To do your addition, do it with the seconds first, then format.
 
Back
Top