Solved

Split Time Period Into Hour Components

Posted on 2004-10-07
7
194 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now