Solved

Split Time Period Into Hour Components

Posted on 2004-10-07
7
213 Views
Last Modified: 2012-05-05
I have a series of response times to various jobs. The problem is that these jobs often span across two hours. What I am trying to do is calculate for each hour of the day exactly how many minutes were used for each response time.

I.e:  So if a job started at 6.30 am and finished at 7.10 am i want to assing hour 6 30 minutes of response time and hour 7 10 minutes.

This gets more difficult when the job span three hours, i.e: starts at 6.30 and finishes at 8.10, here I want to assign hour 6 30 mins, hour 7 60 mins and hour 8 10 mins.

Any Ideas????
0
Comment
Question by:GrantLCampbell
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 12253858
To get the number of minutes between two dates use DateDiff("m", FirstDateTime, SecondDateTime)

Not sure what you mean by 'assign'.

Hope this helps.
-Jim
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12253971
Private Function HowManyMinutes(ByVal BeginTime As Date, EndTime As Date) As Long
HowManyMinutes = DateDiff("n", BeginTime, EndTime)
End Function

Private Sub Command1_Click()
MsgBox HowManyMinutes("6:30 AM", "8:10 AM")
End Sub

S
0
 

Author Comment

by:GrantLCampbell
ID: 12254023
Sorry guys, not sure I explained m,yself properly, might help I tell you waht I am trying to achevie.

I am trying to work out utilisation for vehicles. At the moment I look at the amount of time a vehcile was working for any given job, if that job starts in one hour and finishes in the next at the moment I attribute all of the job time to the starting hour. The problem is I get a vehicle with a total of 1 hour available working for a total over one hour.

What I am trying to do is split the work time for the vehicle into the hours that it occurs. That way I will not get utilisation over 100%.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 65

Expert Comment

by:Jim Horn
ID: 12254040
The logic of this sounds ugly to code, and does not accurately reflect the vehicle's actual usage.  

How exactly would recording the actual usage, in minutes, result in utilization over 100%?
0
 

Author Comment

by:GrantLCampbell
ID: 12254151
The problem occurs because I work out utilisation by hour of day and day of week to implemnt roster design. So when I break utilisation into hourly blocks and a job took longer than the hour available the result is utilisation above 100%.

I am reasonably happy with the accuracy I get from my data now but was wondering if it is possible to apportion the times correctly.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12254258
It's ugly but - sorry but at  11:30pm I have trouble thinking up variable names:

This function returns a variant array. The first item is the number of minutes in the first hour used, the last is the number of minutes in the final hour used, the ones in the middle (if applicable) are the number of minutes in the intervening hours (always sixty of course)

Public Function GetHourlySomething(ByVal StartTime As Date, ByVal EndTime As Date) As Variant
    Dim nMinutes As Long
    Dim nStartMinute As Long
    Dim nEndMinutes As Long
    Dim vHourlyThings As Variant
    Dim i As Long
   
    ReDim vHourlyThings(0)
   
    nStartMinute = DatePart("n", StartTime)
   
    nMinutes = DateDiff("n", StartTime, EndTime)
   
    If nMinutes + nStartMinute <= 60 Then
        vHourlyThings(0) = nMinutes
        GetHourlySomething = vHourlyThings
        Exit Function
    Else
        vHourlyThings(0) = 60 - nStartMinute
        nMinutes = nMinutes - vHourlyThings(0)
    End If
   
    nEndMinutes = nMinutes Mod 60
   
    ReDim Preserve vHourlyThings(Int(nMinutes / 60) + IIf(nEndMinutes = 0, 0, 1))
   
    For i = 1 To Int(nMinutes / 60)
        vHourlyThings(i) = 60
    Next
   
    If nEndMinutes <> 0 Then
        vHourlyThings(i) = nEndMinutes
    End If
   
    GetHourlySomething = vHourlyThings
End Function
0
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 250 total points
ID: 12254296
Further: If a job starts at 6.30am and ends at 7.10am the array will be 30,10.
If a job starts at 6.30am and ends at 8.10am the array will be 30,60,10.
If a job starts at 6.30am and ends at 9.10am the array will be 30,60,60,10.
If a job starts at 6.10am and ends at 6.30am the array will be 20.
 
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question