473,729 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subtract MULTIPLE time segments from a single time segment to calculate cycle time

Hi all
Im working on productivity calculations (Time calculations) and need
some help in coding.
Database Tool:MS-Access 2003.

The general operator punch-in time is 5:30 AM and the punch-out time is
2:00PM. The Break times are
1) 9:30 AM to 9:45 AM
2) 11:00AM to 11:30 AM
3) 12:30PM to 12:45 PM

Now, suppose an operator starts working on a fresh batch of parts @
7:00AM MONDAY morning and finishes the batch @ 7:00AM TUESDAY Morning,
I need to get answer something like this:

24 hrs(7:00AM Mon - 7:00AM Tue) MINUS 15 Minutes(9:30 AM - 9:45 AM)
MINUS 30 Minutes(11:00AM - 11:30 AM) MINUS 15 Minutes(12:30PM - 12:45
PM) MINUS 15hrs & 30Min (2:00PM Mon till 5:30AM Tue)

That is 7.5 hours.

Im creating a database of operators and 4 different operations and I
need this calculations to be made. The catch is that the operator could
start processing a fresh batch of parts any time of the day and could
finish any given time in a day.

I need to subtract the appropriate break times.

Any help in coding is greatly appreciated.

Dec 19 '05 #1
5 6513
On 19 Dec 2005 15:08:57 -0800, cv****@gmail.co m wrote:
Hi all
Im working on productivity calculations (Time calculations) and need
some help in coding.
Database Tool:MS-Access 2003.

The general operator punch-in time is 5:30 AM and the punch-out time is
2:00PM. The Break times are
1) 9:30 AM to 9:45 AM
2) 11:00AM to 11:30 AM
3) 12:30PM to 12:45 PM

Now, suppose an operator starts working on a fresh batch of parts @
7:00AM MONDAY morning and finishes the batch @ 7:00AM TUESDAY Morning,
I need to get answer something like this:

24 hrs(7:00AM Mon - 7:00AM Tue) MINUS 15 Minutes(9:30 AM - 9:45 AM)
MINUS 30 Minutes(11:00AM - 11:30 AM) MINUS 15 Minutes(12:30PM - 12:45
PM) MINUS 15hrs & 30Min (2:00PM Mon till 5:30AM Tue)

That is 7.5 hours.

Im creating a database of operators and 4 different operations and I
need this calculations to be made. The catch is that the operator could
start processing a fresh batch of parts any time of the day and could
finish any given time in a day.

I need to subtract the appropriate break times.

Any help in coding is greatly appreciated.


I'm beginning to sound like a broken record:

What have you tried to do? Show your work. How is it not working?

mike

Dec 19 '05 #2
I don't have all the details worked out, but you might look at
something like

DateDiff("d",[Start Time],[End Time])*24+Hour([End Time]-[Start
Time])+Minute([End Time]-[Start Time])/60

[Start Time] and [End Time] includes a date as well. For example
12/19/2005 07:00:00 AM and 12/20/2005 07:00:00 AM.

Now if you have users "clocking" in and out of Access look at the
timer() function. This calulates the number of seconds after midnight
and you can store that in a table. Real easy to calculate time but
assumes the date is the same so you have to work around that.
Again, I don't have all the bugs worked out, but maybe this will help.

Dec 20 '05 #3
cv****@gmail.co m wrote:
Hi all
Im working on productivity calculations (Time calculations) and need
some help in coding.
Database Tool:MS-Access 2003.

The general operator punch-in time is 5:30 AM and the punch-out time is
2:00PM. The Break times are
1) 9:30 AM to 9:45 AM
2) 11:00AM to 11:30 AM
3) 12:30PM to 12:45 PM

Now, suppose an operator starts working on a fresh batch of parts @
7:00AM MONDAY morning and finishes the batch @ 7:00AM TUESDAY Morning,
I need to get answer something like this:

24 hrs(7:00AM Mon - 7:00AM Tue) MINUS 15 Minutes(9:30 AM - 9:45 AM)
MINUS 30 Minutes(11:00AM - 11:30 AM) MINUS 15 Minutes(12:30PM - 12:45
PM) MINUS 15hrs & 30Min (2:00PM Mon till 5:30AM Tue)

That is 7.5 hours.

Im creating a database of operators and 4 different operations and I
need this calculations to be made. The catch is that the operator could
start processing a fresh batch of parts any time of the day and could
finish any given time in a day.

I need to subtract the appropriate break times.

Any help in coding is greatly appreciated.


I would write a public function to count the number of 15 minute breaks
between two general punch-in and punch-outs that include the date and
time. The break from 11:00 AM to 11:30 AM would count as two 15 minute
breaks. Then the number of breaks divided by four should give the
number of hours to subtract for breaks. Try:

Public Function CountBreaks(dtI n As Date, dtOut As Date) As Integer
Dim BreakStart(5) As Date
Dim BreakEnd(5) As Date
Dim dtTest As Date
Dim intI As Integer
Dim NBreaksPerDay As Integer

NBreaksPerDay = 4
CountBreaks = 0
If dtIn >= dtOut Then Exit Function
BreakStart(1) = "9:30 AM"
BreakEnd(1) = "9:45 AM"
BreakStart(2) = "11:00 AM"
BreakEnd(2) = "11:15 AM"
BreakStart(3) = "11:15 AM"
BreakEnd(3) = "11:30 AM"
BreakStart(4) = "12:30 PM"
BreakEnd(4) = "12:45 PM"
'Back up starting time to beginning of 15 minute interval
dtTest = DateAdd("n", -DatePart("n", dtIn) Mod 15, dtIn)
Do While dtTest <= dtOut
For intI = 1 To NBreaksPerDay
If Format(dtTest, "hh:nn") = Format(BreakEnd (intI), "hh:nn") Then
CountBreaks = CountBreaks + 1
End If
Next intI
dtTest = DateAdd("n", 15, dtTest)
Loop
End Function

It would be used in a query something like:

SELECT CountBreaks(Pun chIn, PunchOut) / 4 AS BreakTimeHrs,
DateDiff('n', PunchIn, PunchOut) / 60 - [BreakTimeHrs] AS ActualHours
FROM tblTimeTickets;

Perhaps an alternative SQL statement can be constructed that does the
counting instead. I didn't try to get clever by using the date
representation internals in order to provide a shortcut for some of the
calculations. The BreakStart and BreakEnd arrays can also be passed
into the function as arguments. Use the UBound function to get
NBreaksPerDay if you are passing in the arrays. Note: I didn't do much
testing of this function.

Now that we're warmed up, let's apply this to your problem.

For, say, Operator 1, Batch 1 and Operation 1:

PI = 7:00 AM Monday
PO = 2:00 PM Monday

PI = 5:30 AM Tuesday
PO = 7:00 AM Tuesday

So these need to be separate records in tblTimeTickets. Having Access
look for a separate Operation PI to get the PO is a little more
challenging but it's what I'm about to be asked to do.

The first calculation will take one hour away from the seven hours
worked. The second calculation will simply add the 1.5 hours worked
with no BreakTimeHrs subtracted. This suggests something like a query
that uses a SUM of ActualHours with GROUP BY OperatorID, BatchID,
OperationID. There are other potential twists as well that complicate
things when you try to implement this in the real world.

Hope this helps,

James A. Fortune
CD********@Fort uneJames.com

Dec 20 '05 #4
CD********@Fort uneJames.com wrote:
cv****@gmail.co m wrote:
Hi all
Im working on productivity calculations (Time calculations) and need
some help in coding.
Database Tool:MS-Access 2003.

The general operator punch-in time is 5:30 AM and the punch-out time is
2:00PM. The Break times are
1) 9:30 AM to 9:45 AM
2) 11:00AM to 11:30 AM
3) 12:30PM to 12:45 PM

Now, suppose an operator starts working on a fresh batch of parts @
7:00AM MONDAY morning and finishes the batch @ 7:00AM TUESDAY Morning,
I need to get answer something like this:

24 hrs(7:00AM Mon - 7:00AM Tue) MINUS 15 Minutes(9:30 AM - 9:45 AM)
MINUS 30 Minutes(11:00AM - 11:30 AM) MINUS 15 Minutes(12:30PM - 12:45
PM) MINUS 15hrs & 30Min (2:00PM Mon till 5:30AM Tue)

That is 7.5 hours.

Im creating a database of operators and 4 different operations and I
need this calculations to be made. The catch is that the operator could
start processing a fresh batch of parts any time of the day and could
finish any given time in a day.

I need to subtract the appropriate break times.

Any help in coding is greatly appreciated.

...
Perhaps an alternative SQL statement can be constructed that does the
counting instead. I didn't try to get clever by using the date
representation internals in order to provide a shortcut for some of the
calculations. The BreakStart and BreakEnd arrays can also be passed
into the function as arguments. Use the UBound function to get
NBreaksPerDay if you are passing in the arrays. Note: I didn't do much
testing of this function.


Here's a rudimentary and nearly totally untested start at using SQL to
do the same thing:

tblTimeTickets
TTID AutoNumber
PunchIn Date/Time
PunchOut Date/Time
TTID PunchIn PunchOut
1 12/19/05 9:15:00 AM 12/23/05 10:30:00 AM
2 12/22/05 9:30:00 AM 12/23/05 5:30:00 PM

tblBreaks
BID AutoNumber
BreakStart Date/Time formatted h:nn ampm
BreakEnd Date/Time formatted h:nn ampm
BID BreakStart BreakEnd
1 9:30 AM 9:45 AM
2 11:00 AM 11:15 AM
3 11:15 AM 11:30 AM
4 12:30 PM 12:45 PM

qryCountBreaks:
SELECT TTID, BreakStart, BreakEnd, IIf(Abs(Int(Pun chIn)+(BreakEnd )
Between PunchIn And
Punchout)=0,0,D ateDiff('n',Int (PunchIn)+(Brea kEnd),PunchOut) \60\24)+1
AS CountBreaks FROM tblTimeTickets, tblBreaks;

!qryCountBreaks :
TTID BreakStart BreakEnd CountBreaks
1 9:30 AM 9:45 AM 5
2 9:30 AM 9:45 AM 2
1 11:00 AM 11:15 AM 4
2 11:00 AM 11:15 AM 2
1 11:15 AM 11:30 AM 4
2 11:15 AM 11:30 AM 2
1 12:30 PM 12:45 PM 4
2 12:30 PM 12:45 PM 2

Analysis:

The query is not quite correct as it stands. It uses the BreakEnd
value on the day of PunchIn to see if the value lies between the
PunchIn and PunchOut. If it does, that one is counted and one more is
added for each 24 hour period after that BreakEnd value that is
contained between PunchIn and PunchOut. A BreakEnd time slightly after
midnight needs to be considered. The test example using some poor
workaholics avoids some obvious problems conveniently. I also didn't
test to see if 59.75 minutes gets converted to 60 by the DateDiff
function. DateDiff using hours proved unsatisfactory. I probably
should have gone directly to the representation of dates as a Double
value to determine this difference. Post back if you need more hints.

James A. Fortune
CD********@Fort uneJames.com

Dec 20 '05 #5
James
This is pure Genius. It works. Let me play around it a little more and
ask for help if I need some thing. Thanks a Million again.

Dec 20 '05 #6

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

Similar topics

3
6320
by: Ramachandran | last post by:
Hi, I am novice in ASP and am trying to build an online test that records user input one question at a time. So each question is a form by itself. I want to make a single ASP file that will validate all the form results and write it to a database. How can I know which form is calling the ASP file? Also, there may be multiple users accessing the quiz at the same time. Do I have to do anything special for such a case?
9
1871
by: amitavabardhan | last post by:
How Can I extract multiple tiff images into single images through asp programming? Is there any free dll's that I can use in ASP to split multiple tiffs into single tiffs? Any suggestion regarding this issue will be highly appreciated.....
0
1193
by: shrishjain | last post by:
Hi All, I want to write a benchmark to calculate the time of each memory access, in my program. Can someone give me an idea how to do that, or may some software which I can use for the same. Thanks, Shrish
4
2999
by: cyberdrugs | last post by:
Hi guys 'n gals, I have a string which contains multiple spaces, and I would like to convert the multiple spaces into single spaces. Example Input: the quick brown fox jumps over the lazy dog Example Output: the quick brown fox jumps over the lazy dog
5
6371
by: polturgiest | last post by:
hie all i got a form <form name="TEST" method=POST action="test.php"> <input type="text" name="MyInput"> <input type="submit" name="ACTION" value="SAVE">
2
2121
by: Lancelot | last post by:
Hello everyone. This is my first post here, but I've been looking for answer many time. I have a crazy idea in my head and since I am quite a newby to python, I am not sure where to start or if it's evenly possible. I wonder if you can calculate the time of respond of a wireless system to evaluate the distance of this device from the computer. I tought of a wireless mouse. Is there a even that you can send, check the local time, wait...
8
1630
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi just wondering if anyone had any ideas on how to do this in C#. I am trying to get the total time of several start and stop time data entries. For example the input data looks like starttime endtime 3:00pm 4:00pm 6:00pm 7:00pm. 6:30pm 7:00pm 3:00pm 3:30pm It would be easy but I do not want to count any overlapped times. For
17
4799
by: yuvang | last post by:
Hi all I have a mdb with login name and password form. There are several login names, i defined through a table "User_login". Here the problem is at a time a single user is able to login in multible system, which i want to restrict. here is the code which i i am using for login check..... Private Sub cmblogin_Click() Static intlogonattempts As Integer
2
3342
by: Guruganesh | last post by:
i have to calculate the time diference of two file names namely File 1: CBE03KMD_2010_03_08_23_06_36.upl File 2: CBE03KMD_2010_03_08_22_11_47.upl see the date is same but the time is also mentioned in the file name. i need a function to calculate the time difference between the two file names.
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.