473,418 Members | 2,003 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,418 software developers and data experts.

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 6497
On 19 Dec 2005 15:08:57 -0800, cv****@gmail.com 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.com 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(dtIn 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(PunchIn, 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********@FortuneJames.com

Dec 20 '05 #4
CD********@FortuneJames.com wrote:
cv****@gmail.com 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(PunchIn)+(BreakEnd)
Between PunchIn And
Punchout)=0,0,DateDiff('n',Int(PunchIn)+(BreakEnd) ,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********@FortuneJames.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
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...
9
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...
0
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. ...
4
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 ...
5
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
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...
8
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...
17
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...
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...
0
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...

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.