I have a Start and End time in a table which I find the total time by using
diff: (DateDiff("n",[Start],[End]))
I then want to round this figure up to the nearest 15mins (billing period).
I tried
rounddif: CInt([diff]/15)*15
but it rounds up or down to the nearest 15. I want to force it to always round up.
eg. 6min would round to 15, 33mins would round to 45, etc
Any help would be greatly appreciated.
I am using MS Access 2007
13 4101 FishVal 2,653
Recognized Expert Specialist
I have a Start and End time in a table which I find the total time by using
diff: (DateDiff("n",[Start],[End]))
I then want to round this figure up to the nearest 15mins (billing period).
I tried
rounddif: CInt([diff]/15)*15
but it rounds up or down to the nearest 15. I want to force it to always round up.
eg. 6min would round to 15, 33mins would round to 45, etc
Any help would be greatly appreciated.
I am using MS Access 2007
Hi, tmdan.
Try this
rounddif: Round([diff]/15)*15
Hi, thanks for that but it still returns the same result.
Any other ideas?
ADezii 8,834
Recognized Expert Expert
Hi, thanks for that but it still returns the same result.
Any other ideas?
This little Function will perform the proper 'Round Up at 15 min. Intervals' for a differential of up to 2 hours: - Public Function fRoundUpTo15(MinDiff As Integer) As Integer
-
Select Case MinDiff
-
Case 1 To 15
-
fRoundUpTo15 = 15
-
Case 16 To 30
-
fRoundUpTo15 = 30
-
Case 31 To 45
-
fRoundUpTo15 = 45
-
Case 46 To 60
-
fRoundUpTo15 = 60
-
Case 61 To 75
-
fRoundUpTo15 = 75
-
Case 76 To 90
-
fRoundUpTo15 = 90
-
Case 91 To 105
-
fRoundUpTo15 = 105
-
Case 106 To 120
-
fRoundUpTo15 = 120
-
End Select
-
End Function
- "A time difference of 63 minutes Rounds Up to: " & fRoundUpTo15(63) & " minutes"
OUTPUT: - A time difference of 63 minutes Rounds Up to: 75 minutes
ADezii 8,834
Recognized Expert Expert
Hi, thanks for that but it still returns the same result.
Any other ideas?
Actually, I like my 2nd idea better: - Dim diff As Integer, diffRoundUp As Integer
-
-
If diff Mod 15 = 0 Then
-
diffRoundUp = diff
-
Else
-
diffRoundUp = diff + (15 - (diff Mod 15))
-
End If
Actually, I like my 2nd idea better: - Dim diff As Integer, diffRoundUp As Integer
-
-
If diff Mod 15 = 0 Then
-
diffRoundUp = diff
-
Else
-
diffRoundUp = diff + (15 - (diff Mod 15))
-
End If
Sorry, I'm a bit of a novice with VB so I was trying to acheive this with a query.
I have a text box on my form called diff with =(DateDiff("n",[Start],[End])) as the control source.
I have created a second text box called diffRoundUp but where do I put this code so that this box displays the rounded figure?
Thanks again for your help
ADezii 8,834
Recognized Expert Expert
Sorry, I'm a bit of a novice with VB so I was trying to acheive this with a query.
I have a text box on my form called diff with =(DateDiff("n",[Start],[End])) as the control source.
I have created a second text box called diffRoundUp but where do I put this code so that this box displays the rounded figure?
Thanks again for your help
Placing this code in your Form's Current() Event should do the trick:[ - Private Sub Form_Current()
-
If Not Me.NewRecord And Not IsNull(Me![Start]) And Not IsNull(Me![End]) Then '*
-
Dim intMinDiff As Integer
-
-
intMinDiff = DateDiff("n", Me![Start], Me![End])
-
-
If intMinDiff Mod 15 = 0 Then
-
Me![diffRoundUp] = intMinDiff
-
Else
-
Me![diffRoundUp] = intMinDiff + (15 - (intMinDiff Mod 15))
-
End If
-
Else
-
Me![diffRoundUp] = Null
-
End If
-
End Sub
FishVal 2,653
Recognized Expert Specialist
Hi, tmdan.
You may advantageously use Int() function that always rounds down.
rounddif: -Int(-[diff]/15)*15
Hi, tmdan.
You may advantageously use Int() function that always rounds down.
rounddif: -Int(-[diff]/15)*15
Thanks, but I want to always round up. Do you know of a variation of it to go up?
Placing this code in your Form's Current() Event should do the trick:[ - Private Sub Form_Current()
-
If Not Me.NewRecord And Not IsNull(Me![Start]) And Not IsNull(Me![End]) Then '*
-
Dim intMinDiff As Integer
-
-
intMinDiff = DateDiff("n", Me![Start], Me![End])
-
-
If intMinDiff Mod 15 = 0 Then
-
Me![diffRoundUp] = intMinDiff
-
Else
-
Me![diffRoundUp] = intMinDiff + (15 - (intMinDiff Mod 15))
-
End If
-
Else
-
Me![diffRoundUp] = Null
-
End If
-
End Sub
Thats fantastic. Thanks a lot for your help
FishVal 2,653
Recognized Expert Specialist
Thanks, but I want to always round up. Do you know of a variation of it to go up?
If you take a closer look to the expression you'll see that it rounds up (rounding down negative number means rounding up its absolute value).
-Int(-16/15)*15=30 for example
ADezii 8,834
Recognized Expert Expert
Thats fantastic. Thanks a lot for your help
Anytime, glad it worked out for you.
ADezii 8,834
Recognized Expert Expert
If you take a closer look to the expression you'll see that it rounds up (rounding down negative number means rounding up its absolute value).
-Int(-16/15)*15=30 for example
Interesting approach FishVal, it's almost like you have to think negatively (LOL).
FishVal 2,653
Recognized Expert Specialist
Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
:-P
Nothing new.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Norvin Laudon |
last post by:
Hi,
Can somebody explain the following, from the MSDN documentation for the
"System.Convert.ToInt32(double)" function
<quote>
Return Value
value rounded to the nearest 32-bit signed...
|
by: spebola |
last post by:
I am using vb.net 2003 professional and I get the following results
when using the round method:
dim Amount as decimal = 180.255
Amount = Amount.Round(Amount, 2)
Amount now contains 180.25. ...
|
by: Zorpiedoman |
last post by:
Howcome:
Dim D as decimal = .5D
msgbox d.Round(D, 0)
this returns "0"
Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!!
Documentation says this, but what the heck are...
|
by: Jiri Nemec |
last post by:
Hello all,
I have got one table with rounding values, table contains
prices and round types.
id price_from price_to rounding
1 0 1500 0.1
2 1500 ...
|
by: cj |
last post by:
Lets assume all calculations are done with decimal data types so things
are as precise as possible.
When it comes to the final rounding to cut a check to pay dividends for
example in VB rounding...
| |
by: jdrott1 |
last post by:
i'm trying to round my currency string to end in 9. it's for a
pricing application.
this is the function i'm using to get the item in currency:
FormatCurrency(BoxCost, , , , TriState.True)
if...
|
by: Spoon |
last post by:
Hello everyone,
I don't understand how the lrint() function works.
long lrint(double x);
The function returns the nearest long integer to x, consistent with the
current rounding mode. It...
|
by: md |
last post by:
Hi
Does any body know, how to round a double value with a specific number
of digits after the decimal points?
A function like this:
RoundMyDouble (double &value, short numberOfPrecisions)
...
|
by: jacob navia |
last post by:
Hi
"How can I round a number to x decimal places" ?
This question keeps appearing. I would propose the following
solution
#include <float.h>
#include <math.h>
|
by: bdsatish |
last post by:
The built-in function round( ) will always "round up", that is 1.5 is
rounded to 2.0 and 2.5 is rounded to 3.0.
If I want to round to the nearest even, that is
my_round(1.5) = 2 # As...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |