473,287 Members | 1,395 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,287 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 2887
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.