473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calculating time

Hi!

I have a table with a StartTime and EndTime and want to calculate number of
hours worked. Is it possible to get a "Number" answer?

E.g.
9:00am (StartTime) worked to 4:00pm (EndTime) = 7 (Hours worked)

I would only ever have a single day so it doensn't need to span over
different dates.

Thanks in advance.
Nov 21 '07 #1
4 1860
The function datediff is your friend in this scenario.

An example is
datediff("H", #09:00#, #17:30#) which would return 8 as a value.

Hope that this helps,

Kind Regards
Anthony Moore

IT Excellence
Nov 21 '07 #2
On Nov 21, 6:53 am, Anthos <anth...@itexcellence.com.auwrote:
The function datediff is your friend in this scenario.

An example is
datediff("H", #09:00#, #17:30#) which would return 8 as a value.

Hope that this helps,

Kind Regards
Anthony Moore

IT Excellence
DateDiff counts boundaries, in this case the number of times the big
hand is at the twelve between the start and stop times.
Unless this is taken into consideration, its return value may not be
as useful as we would like.

Take someone who works from
#9:01:00 AM#
#5:59:00 PM#
He or she works just two minutes short of nine hours.

But DateDiff("H", #9:01:00 AM#, #5:59:00 PM#) returns 8.
If I were being paid for eight hours for working for almost nine hours
I might think I was being treated unfairly.

I have a little function that could be more accurate than a naked
DateDiff; it is UNTESTED AIR CODE but it might serve as a starting
point for the original poster.

Public Function MyHours@( _
ByVal Time1 As Date, _
ByVal Time2 As Date, _
Optional ByVal RoundTo& = 15)
' RoundTo is a number of minutes
' 15 rounds to nearest quarter of an hour
MyHours = Round(CCur(Abs(DateDiff("n", Time1, Time2))) / RoundTo, 0) *
Round(RoundTo / 60, 2)
End Function

For
#9:01:00 AM#
#5:59:00 PM#
MyHours returns 9.
Nov 21 '07 #3
Hi,
you could do something like this
if text1=9:01 and text3=17:57

mytotal = DateDiff("n", Me.Text1, Me.Text3)
myhour = mytotal \ 60 'returns non rounded integer part
myminutes = mytotal Mod 60 'returns remainder
mydisplay = myhour & " hrs and " & myminutes & " minutes"

mydisplay= 8 hrs and 56 minutes
bobh.

On Nov 21, 3:44 am, "scott" <scott.nos...@maneyacts.comwrote:
Hi!

I have a table with a StartTime and EndTime and want to calculate number of
hours worked. Is it possible to get a "Number" answer?

E.g.
9:00am (StartTime) worked to 4:00pm (EndTime) = 7 (Hours worked)

I would only ever have a single day so it doensn't need to span over
different dates.

Thanks in advance.
Nov 21 '07 #4
Here you go :-)

Sub WorkTime()
mytotal = DateDiff("n", #9:01:00 AM#, #5:56:00 PM#)
myhours = Fix(mytotal / 60)
myminut = mytotal Mod 60
myWTime = myhours & " Hours and " & myminut & " Minutes"
End Sub

this should get you what you need, just swap in some variables where
you need to, or maybe make it a function to return the data you
want....

Cheers

The Frog
Nov 22 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any...
0
by: Kasp | last post by:
Hi there, I am trying to make an OLAP cube on a table having two columns (datetime, Number_of_times_an_event_occured). My dimension is time and I want to measure the Min and Max times an event...
1
by: jlm | last post by:
I have a form which feeds table (TblEmpLeave) of Employee Leave Time (time taken off for Administrative, Annual, Sick, Compensation leave). I have EmpID, LeaveDate, LeaveType, LeaveHours fields on...
3
by: Miller | last post by:
Hi, Can someone tell me how to calculate MFLOPS for the following C# code (on a Pentium 4 2.0 Ghz)? for (i=0; i<n; i++) { for (j=0; j<n; j++) { for (k=0; k<n; k++)
12
by: jUrner | last post by:
Hello all I have the problem of how to calculate the resolution of the system clock. Its now two days of head sratching and still there is nothing more than these few lines on my huge white...
25
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
25
by: Blaize | last post by:
Hi, I'm having an issue trying to calculate time. Its okay if the value does not exceed 24 hours otherwise I get a date and hours listed. For example, I have a loop which looks through a table...
10
freddieMaize
by: freddieMaize | last post by:
Hi there, I need to hit few list of sites from my application and find the response time of those site and sort them (which ever is opening first will sit at the top). I have done the same using...
3
by: mfaisalwarraich | last post by:
Hi everybody. I have some problem while calculating time. i have employees who are working on hourly basis. i want to calculate the time. for example if an employee start working at 11:00pm...
4
by: Missionary2008 | last post by:
Thank you in advance for your help. I'm trying to calculate the Total Time in hours and minutes to complete a job. The way we are calculating it is by taking the Fee paid and dividing that by a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.