?
Solved

Round up to the half hour and full hour

Posted on 2003-03-13
4
Medium Priority
?
469 Views
Last Modified: 2010-05-18
I have three fields in my form:

Arrival_Time
Departure_Time
Billable_Time

I want to automatically populate Billable_Time with a rounded value.

If the elapsed time is more than 5 minutes past the half hour mark, I want to round to the next hour.
example:
1 hour and 4 minutes is billed at 1 hour
1 hour and 5 minutes is billed at 1.5 hours
1 hour and 30 minutes is billed at 1.5 hours
1 hour and 33 minutes is billed at 1.5 hours
1 hour and 35 minutes is billed at 2 hours
1 hour and 50 minutes is billed at 2 hours

I've tried some very wild equations, but never get what I want in all scenarios.
Right now I'm staring at:

Private Sub Billable_time_Enter()
If ([Departure_Time] > [Arrival_Time]) Then
   n = (DateDiff("n", [Arrival_Time], [Departure_Time]) / 60)
    If n < 1 Then
       Billable_time.Value = 1
    Else
       Billable_time.Value = Round(n * 4) / 4
    End If
Else
   Billable_time.Value = (DateDiff("n", [Arrival_Time], [Departure_Time]) + (24 * 60)) / 60
End If

End Sub


This being the line that is making my head swim:
Billable_time.Value = Round(n * 4) / 4






0
Comment
Question by:jasgot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:ecims
ID: 8128613
0
 
LVL 1

Expert Comment

by:IanWorcester
ID: 8128770
Try creating 2 variables:

Hours and Minutes using datediff function

intTotalMinutes=datediff( "n",#11:30#,#12:36#)

This will give intHours=66, the number of minutes elapsed between the times(dates entered).

From this you can use:

intHours=int(intTotalMinutes/60)
intMinutes=intTotalMinutes-(intHours*60)

from this you can see if the minute variable is greater or less than 0 and less that 5, greater than 5 and less than 30, etc

And from that you should be able to conditionally add half hour/hour chunks  to the hour part.

Hop this helps
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 1000 total points
ID: 8129201
Try:
 n = (DateDiff("n", [Arrival_Time], [Departure_Time])-5
 If n<1 Then n=1
 Billable_time.Value = (((n-1)\30)+1)/2
0
 

Author Comment

by:jasgot
ID: 8129812
Thanks shanesuebsahakarn,

That worked like a charm!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

777 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