Time calculation problem

TheShed

New member
Local time
Today, 21:54
Joined
May 6, 2008
Messages
9
Hi there folks, I am trying to calulate the number of hours an employee has worked based on the start and finish times that the user inputs to a form using the following code:-

startTime = txtstartTime.Value
finishTime = txtfinishTime.Value
hoursWorked = [finishTime] - [startTime]

Now this works fine if the start and finish times are on the same day. The problem I am having is that if somebody works through midnight, the calculation falls over.

e.g. if somebody starts at 23:00 and finishes at 01:00 then hoursWorked is 22 hours which is obviously wrong.

Can somebody point me in the direction of how to solve this as I am stumped.

Thanks :D
 
Simple Software Solutions

Many people has come accross this issue. Essesntially what you need to do is to convert both times to minutes, then check if end time is smaller than start time, if so, add 1440 to end time (1440 = minutes in a day) then subtract one from the other and convert back to hours and minutes.

This can be done easily in a function. then use the function to calculate the hours worked.

CodeMaster::cool:
 

Users who are viewing this thread

Back
Top Bottom