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!

Calculated time taken

Status
Not open for further replies.

Kindi

Programmer
Jan 31, 2001
54
0
0
GB
Hi

A user has two input time boxes one for start time and one of end time, once the end time is clicked i wish the total time to be work out between the start and end time, and then to enter this total time in a text box on the same form. On the expression builder how can i do this, i have been trying to use the setvalue function on the macros in Access.

Thanks
 
set the textbox you want to display the total control source to

=datediff("h",timein,timeout)

if you want hours and minutes you can adjust this Or I can post another function
 
Hi

Thanks for the help above, but what i did was in the text box was in the control source i called the expression builder and added as you instructed above:

=DateDiff("h",[StartTime],[EndTime])

But when i run the form, and the start and end times are entered nothing happens, what else can i do, or how can i get the form to refresh? and enter the time difference?

Thanks
 
Here is exactaly what I did

added 3 textboxes to a form
named 1 of them starttime
named the 2nd on endtime
set format of both of these to shorttime
in the 3rd box In the control source I put in

=DateDiff("h",[endtime],[starttime])

when I enter the time in the first box nothing happens
as soon as I enter the time in the Second box and Hit enter the difference in hours displays in the 3rd box

Is this similar to waht you are doing?

 
Hi

Thanks as you suggested, that is what i am trying to do, and it works! thanks.

But if the start time is 09.29 and end time is 9.36, the total is still 0. If i input start time 10.00 and end time 14.00 this brings up 4 hours which is correct.

How do i bring up the time difference in minutes?, and how do u bring up the difference in hours and minutes?

Thank you
 
Hi

Instead of using "h" in the datediff function i used "m", this doesnt work either.

 
Here is a different function to try.

place this in a module and

use like this
=getelapsedtime([endtime]-[starttime])

From MS so you Know its good!!!!

Public Function GetElapsedTime(interval)
'pass as GetElapsedTime(latertime - earliertime)
Dim totalhours As Long, totalminutes As Long, totalseconds As Long
Dim days As Long, hours As Long, Minutes As Long, Seconds As Long

days = Int(CSng(interval))
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
totalseconds = Int(CSng(interval * 86400))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
Seconds = totalseconds Mod 60

GetElapsedTime = days & " Days " & hours & " Hours " & Minutes _
& " Minutes " & Seconds & " Seconds "

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top