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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Time 1

Status
Not open for further replies.

OceanBlue

IS-IT--Management
Aug 15, 2002
54
US
On my form I have fields for StartTime, EndTime, and Log hours

Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.StartTime = Format(Now, "hh:mm:ss AMPM")
End Sub

Private Sub TotalWorkedPgs_AfterUpdate()
Me.EndTime = Format(Now, "hh:mm:ss AMPM")
End Sub

I want to record the time that elapses b/w the 2 times whether it be minutes, hours but I have been unsucessful.

I have tried:

Code:
Private Sub cmdSumbit_Click()
[LogHours] = Format([Starttime] - 1 - [Endtime], "Short Time")
End Sub

Code:
Private Sub cmdSumbit_Click()
LogHours = DateDiff("n", [Starttime], [Endtime])[LogHours] = Format([Starttime] - 1 - [Endtime], "Short Time")
End Sub

But I keep getting 0 in my loghours field

Don't know what i'm doing wrong. Any help will be appreciated.
Thanks


 
[LogHours] = Format(CDate([Endtime]) - CDate([Starttime]), "Short Time")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you PHV:

I tried that and formatted my text box to short time.

That output correctly but I don't know if it is outputting accurately. I did a test:

Start Time 12:04:01 PM
End Time 12:07:00PM

Log Hours: 0:02

This may be a stupid question
Shouldn't that be 0:03
Or is it because it is also accounting the seconds that it is giving me 0:02
 
[LogHours] = CDate([Endtime]) - CDate([Starttime])

And format the text box as h:nn:ss

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you so much PHV it's all working now
 
Here's another question. I wanted to calculate the number of days from the sum of the log hours. But I can't calculate the sum of log hours since it's formatted as time.

I'd need to get the sum of log hours / 8 to get the number of days.

How can I accurately get the sum of the log hours?
 
dear oceanblue,

You've gotten outstanding help from PHV, as I have in the past.

However, I wonder if your last question might be better suited for its own thread, rather than as a continuation.
Just a thought.

Tim

[blue]______________________________________________________________
I love logging onto Tek-Tips. It's always so exciting to see what the hell I
said yesterday.
[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top