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

Finding Hours Worked

Status
Not open for further replies.

snyperx3

Programmer
May 31, 2005
467
US
I have two fields that I'm working with in a table: InTime, and OutTime. These are text fields. Each contain a punch time. For instance: InTime = 14:32, OutTime = 15:01. This is Hours:Minutes. I have to calculate the difference in time between these in an double type format (not the seconds). So in this case it would be .48 as it was 48.3333% of one hour between the two. I have to account for the day changing before the OutTime. Sooo...I have this code:
Code:
dInTime = CInt(Left(rst![InTime], 2)) + CDbl(Format((CInt(Right(rst![InTime], 2)) / 60), "Fixed"))
dOutTime = CInt(Left(rst![OutTime], 2)) + CDbl(Format((CInt(Right(rst![OutTime], 2)) / 60), "Fixed"))
Hours = Hours + IIf(dOutTime > dInTime, dOutTime, dOutTime + 24) - dInTime
This has worked in most cases.

What I want to know is: Is there a better way to find the difference in two times?
-I can easily convert these to a date/time field.



-Pete
 
Have you seen (?):
Working out Total Hours worked (Running over Mid Night)
thread702-996310
 
No I hadn't seen that.

I guess I will be converting my text fields to date/time fields then.

Thanks.

-Pete
 
You might try adapting this:
Code:
    Dim intDiff As Integer
    Dim datBegin As Date
    Dim datEnd As Date
    
    datBegin = CDate(Me!cboBegDate.Value) [COLOR=green]'combo box [/color]
    datEnd = CDate(Me!txtEndingDate.Value)[COLOR=green]'text box value[/color]
    intDiff = DateDiff("d", datBegin, datEnd)

Of course, you don't have to use input from controls, you could just use variables or actual dates e.g. #01/01/2005# format.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top