473,396 Members | 1,748 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.

How to calculate a finish time

116 100+
I have a magazine that prints 2000 copies an hour. Therefore if i have a start date of 28/05/10 and start time of 18:30 and wish to produce 3000 copies I want to return 28/05/10 in the finish date and 20:00 in the finish time as an estimate of the finish time. Can anyone advice me on this.
May 29 '10 #1

✓ answered by ADezii

I have arrived at a sort of convoluted Solution. I would wait and see if someone comes up with something better.
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalcFinish(intNumOfCopies As Integer, dteStartDate As Date, dteStartTime As Date) As String
  2. Dim dteStartDateAndTime As Date
  3. Dim dteFinishDateAndTime As Date
  4. Const conCOPIES_PER_HOUR As Integer = 2000
  5.  
  6. 'Combine Start Date and Time into a Single Component
  7. dteStartDateAndTime = CDate(Format$(dteStartDate, "mm/dd/yyyy") & " " & dteStartTime)
  8.  
  9. 'Add the required Number of Minutes based on the Number of Copies requested to the
  10. 'combinied Start Date and Time
  11. dteFinishDateAndTime = DateAdd("n", (intNumOfCopies / conCOPIES_PER_HOUR) * 60, dteStartDateAndTime)
  12.  
  13. 'Break Finish Date/Time down into 2 seperate Components, separated by a Comma
  14. fCalcFinish = Format$(dteFinishDateAndTime, "mm/dd/yyyy") & "," & _
  15.               Format$(dteFinishDateAndTime, "h:nn AM/PM")
  16. End Function
Expand|Select|Wrap|Line Numbers
  1. 'Use the Split() Function to retrieve both the Date (1st Element of the Array),
  2. 'and the Time which would be the 2nd Element of the Array
  3. Debug.Print "Finish Date: " & Split(fCalcFinish(3000, #5/28/2010#, #6:30:00 PM#), ",")(0)
  4. Debug.Print "Finish Time: " & Split(fCalcFinish(3000, #5/28/2010#, #6:30:00 PM#), ",")(1)
produces
Expand|Select|Wrap|Line Numbers
  1. Finish Date: 05/28/2010
  2. Finish Time: 8:00 PM
Expand|Select|Wrap|Line Numbers
  1. 'Use the Split() Function to retrieve both the Date (1st Element of the Array),
  2. 'and the Time which would be the 2nd Element of the Array
  3. Debug.Print "Finish Date: " & Split(fCalcFinish(20000, #5/28/2010#, #6:30:00 PM#), ",")(0)
  4. Debug.Print "Finish Time: " & Split(fCalcFinish(20000, #5/28/2010#, #6:30:00 PM#), ",")(1)
produces
Expand|Select|Wrap|Line Numbers
  1. Finish Date: 05/29/2010
  2. Finish Time: 4:30 AM

13 2890
ADezii
8,834 Expert 8TB
@jacc14
  1. Create a Public Function to do the work:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fCalcFinish(intNumOfCopies As Integer, dteStartDate As Date) As Date
    2.   'Pass to this Function the Number of Copies desired, as well as the Start
    3.   'Date/Time. Based on 2,000 Copies/Hr., it will then add the required Number
    4.   'of Minutes to the Start Date/Time and return the Finish Date/Time
    5.   fCalcFinish = DateAdd("n", (intNumOfCopies / 2000) * 60, dteStartDate)
    6. End Function
  2. Call the Function:
    Expand|Select|Wrap|Line Numbers
    1. MsgBox "The Finish Date/Time for this Project is: " & fCalcFinish(3000, #5/28/2010 6:30:00 PM#)
  3. View the Results (in a Message Box):
    Expand|Select|Wrap|Line Numbers
    1. The Finish Date/Time for this Project is: 5/28/2010 8:00:00 PM
  4. Any questions, feel free to ask.
May 29 '10 #2
jacc14
116 100+
@ADezii
Hi thank you for this. unfortunately i have had to split out the date and time fields as the user is required to put in times and i dont want him to enter a date everytime as well . Would this be possible. I therefore have 4 fields.

start date start time finish date finish time.

I would want my results posting to the last 2 fields using the no of copies per hour and start date and time

Best regards
Christine
May 29 '10 #3
ADezii
8,834 Expert 8TB
@jacc14
  1. Hello Christine, would there ever be a case where the Start Date and End Date are not the same?
  2. Would the Time Differential ever span Midnight?
May 29 '10 #4
ADezii
8,834 Expert 8TB
I have arrived at a sort of convoluted Solution. I would wait and see if someone comes up with something better.
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalcFinish(intNumOfCopies As Integer, dteStartDate As Date, dteStartTime As Date) As String
  2. Dim dteStartDateAndTime As Date
  3. Dim dteFinishDateAndTime As Date
  4. Const conCOPIES_PER_HOUR As Integer = 2000
  5.  
  6. 'Combine Start Date and Time into a Single Component
  7. dteStartDateAndTime = CDate(Format$(dteStartDate, "mm/dd/yyyy") & " " & dteStartTime)
  8.  
  9. 'Add the required Number of Minutes based on the Number of Copies requested to the
  10. 'combinied Start Date and Time
  11. dteFinishDateAndTime = DateAdd("n", (intNumOfCopies / conCOPIES_PER_HOUR) * 60, dteStartDateAndTime)
  12.  
  13. 'Break Finish Date/Time down into 2 seperate Components, separated by a Comma
  14. fCalcFinish = Format$(dteFinishDateAndTime, "mm/dd/yyyy") & "," & _
  15.               Format$(dteFinishDateAndTime, "h:nn AM/PM")
  16. End Function
Expand|Select|Wrap|Line Numbers
  1. 'Use the Split() Function to retrieve both the Date (1st Element of the Array),
  2. 'and the Time which would be the 2nd Element of the Array
  3. Debug.Print "Finish Date: " & Split(fCalcFinish(3000, #5/28/2010#, #6:30:00 PM#), ",")(0)
  4. Debug.Print "Finish Time: " & Split(fCalcFinish(3000, #5/28/2010#, #6:30:00 PM#), ",")(1)
produces
Expand|Select|Wrap|Line Numbers
  1. Finish Date: 05/28/2010
  2. Finish Time: 8:00 PM
Expand|Select|Wrap|Line Numbers
  1. 'Use the Split() Function to retrieve both the Date (1st Element of the Array),
  2. 'and the Time which would be the 2nd Element of the Array
  3. Debug.Print "Finish Date: " & Split(fCalcFinish(20000, #5/28/2010#, #6:30:00 PM#), ",")(0)
  4. Debug.Print "Finish Time: " & Split(fCalcFinish(20000, #5/28/2010#, #6:30:00 PM#), ",")(1)
produces
Expand|Select|Wrap|Line Numbers
  1. Finish Date: 05/29/2010
  2. Finish Time: 4:30 AM
May 29 '10 #5
jacc14
116 100+
@ADezii
Thank you for that I will give it a go. In answer to the early question, yes it could go over midnight which is where i hit a problem.

Cheers
Christine.
May 29 '10 #6
ADezii
8,834 Expert 8TB
@jacc14
The code in Post #5 will work, given the Post-Midnight scenario.
May 29 '10 #7
jacc14
116 100+
@ADezii
Exactly what i am looking for . It works a treat.

many thanks
Christine.
May 30 '10 #8
ADezii
8,834 Expert 8TB
@jacc14
Just as a side note, Christine, you should perform some kind of Validation on the Arguments before you pass them to the Function, such as:
  1. The Number of Copies should be > 0 and <= 32,767, the Maximum for an Integer.
  2. If you want a Maximum Number of Copies, and the User enters a Value beyond that, then reset to the Max.
  3. Make sure that the Start Date is actually a Date using IsDate().
  4. Make sure that the Start Time is actually a Date using IsDate().
  5. YaDa, YaDa, YaDa...
May 30 '10 #9
jacc14
116 100+
@ADezii
Hello ADezii

Thank you for your advice. Wonderful. However I wanted to go further and have been experimenting with the code you have sent me.

I am basically wanting to now taken the duration to work back a machine speed. To do this I need the duration to be converted as a decimal. Adapting your code i did the following:

Expand|Select|Wrap|Line Numbers
  1.  Public Function duration(dteStartDate As Date, dteStartTime As Date, dtefinishDate As Date, dtefinishTime As Date) As Double
  2.  
  3. Dim dteStartDateAndTime As Date
  4. Dim dteFinishDateAndTime As Date
  5.  
  6. dteStartDateAndTime = CDate(Format$(dteStartDate, "dd/mm/yyyy") & " " & dteStartTime)
  7. dteFinishDateAndTime = CDate(Format$(dtefinishDate, "dd/mm/yyyy") & " " & dtefinishTime)
  8.  
  9. duration = dteFinishDateAndTime - dteStartDateAndTime
  10.  
  11.  
  12. End Function
  13.  

I dont actually get the results I want and am not sure what i am doing. the results are as follows:

00:15:00 produces 0.0104166666715173
01:00:00 produces 0.0416666666642413

Any ideas please

Thanks
Christine.
May 31 '10 #10
jacc14
116 100+
Hi.

Think I have got it. Its calculating seconds??

Christine.
May 31 '10 #11
ADezii
8,834 Expert 8TB
@jacc14
Sorry Christine, I'm still a little confused, but the following code will give you the Differential as a Fractional Component of a Day (1,440 mins):
Expand|Select|Wrap|Line Numbers
  1. Public Function duration(dteStartDate As Date, dteStartTime As Date, dtefinishDate As Date, dtefinishTime As Date) As Double
  2. Dim dteStartDateAndTime As Date
  3. Dim dteFinishDateAndTime As Date
  4. Dim lngMinsDiff As Long
  5.  
  6. dteStartDateAndTime = CDate(Format$(dteStartDate, "mm/dd/yyyy") & " " & dteStartTime)
  7. dteFinishDateAndTime = CDate(Format$(dtefinishDate, "mm/dd/yyyy") & " " & dtefinishTime)
  8.  
  9. 'Calculate the Difference in Minutes
  10. lngMinsDiff = DateDiff("n", dteStartDateAndTime, dteFinishDateAndTime)
  11.  
  12. 'Return the Difference in Minutes as a Fraction of a Day rounded to 6 Decimal Places
  13. duration = FormatNumber((lngMinsDiff / 1440), 6)
  14. End Function
May 31 '10 #12
jacc14
116 100+
@ADezii
Thanks for your help with this. Result.
Jun 1 '10 #13
ADezii
8,834 Expert 8TB
@jacc14
You are quite welcome.
Jun 1 '10 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

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. ...
7
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
4
by: Qwert | last post by:
Hello, I do: Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString) REM Calculate a bunch of stuff. Some loops and math functions. Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString) but...
5
by: cvisal | last post by:
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...
1
by: ret4rt | last post by:
Hello. I have a task to do which is as follows: I have to do an "id query" on a primary key of my db and then calculate the response time of the query. Task says that i'm able to take screenshots...
7
by: walt | last post by:
Hello, I have been trying to calculate the difference between two date and display the difference in hours and minutes (HH:MM). I can't get it calculate properly and I can't hours and minutes to...
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...
3
by: John Torres | last post by:
how do you calculate total time hours? I have sub total hours for each day and I've been trying to total all the hours. I'm getting odd numbers. Thanks. John
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.