Minutes and seconds

  • Thread starter Thread starter John J.
  • Start date Start date
J

John J.

In a importroutine I have code to show the user how much time the routine
took:

msgbox "This took " & datediff("s", dt1, now) & " seconds."

How can I change this so that the message box for instance will show:

This took 2 minutes and 4 seconds

Thanks,
John
 
Dim lngSeconds As long
Dim strMsg As String
lngSeconds = datediff("s", dt1, Now())
strMsg = "This took " & (lngSeconds \ 60) & " minutes and " & (lngSeconds
Mod 60) & " seconds."
MsgBox strMsg

The backslash performs integer division.
The Mod gives the remainder after division.
 
I'm not sure that there exists a function to do that time-math, but
you could build one ... or search the newsgroups for someone who
already has.

for example, a quick Google search of Access newsgroups showed
Allen Browne's response to a similar problem ...

=[Seconds] \ 60 & Format([Seconds] Mod 60, "\:00")
 
John J. said:
In a importroutine I have code to show the user how much time the routine
took:

msgbox "This took " & datediff("s", dt1, now) & " seconds."

How can I change this so that the message box for instance will show:

This took 2 minutes and 4 seconds

Thanks,
John
Hi John
Here is one way:
===============================================================
Dim iSeconds As Long
iSeconds = DateDiff("s", dt1, Now)
MsgBox "This took " & iSeconds \ 60 & " minutes and " & iSeconds Mod 60 & "
seconds."
===============================================================
Good luck
Harold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top