473,408 Members | 2,734 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,408 software developers and data experts.

Rounding time

Hell all!

How to round a time into 15 minutes period for example

--------------------------
Now is: | After rounding
--------------------------
19:00 | 19:15
19:05 | 19:15
19:12 | 19:15
19:16 | 19:30
19:30 | 19:45
19:36 | 19:45
19:45 | 20:00
20:00 | 20:15

Is it possible to do it by easy way?

Thank you in advance
Marcin
Nov 13 '05 #1
2 4379
Kamyk wrote:
Hell all!

How to round a time into 15 minutes period for example

--------------------------
Now is: | After rounding
--------------------------
19:00 | 19:15
19:05 | 19:15
19:12 | 19:15
19:16 | 19:30
19:30 | 19:45
19:36 | 19:45
19:45 | 20:00
20:00 | 20:15


Write a function that converts the time to the total minutes: ie-

00:13 = 13
01:12 = 72
02:00 = 120

Divide the result by 15, and truncate anything after the decimal point.

Add 1.

Multiply by 15, and reconvert the resulting minutes into time: ie -

15 = 0:15
75 = 01:15
150 = 02:30

If you end up with 24:00, set it equal to 00:00

Nov 13 '05 #2
"Kamyk" <ma**************@poczta.onet.pl> wrote in message news:<cf**********@news.onet.pl>...
Hell all!

How to round a time into 15 minutes period for example

--------------------------
Now is: | After rounding
--------------------------
19:00 | 19:15
19:05 | 19:15
19:12 | 19:15
19:16 | 19:30
19:30 | 19:45
19:36 | 19:45
19:45 | 20:00
20:00 | 20:15

Is it possible to do it by easy way?

Thank you in advance
Marcin

Umm... are you REALLY supposed to round 19:00 to 19:15? (Doesn't look
right!)

Shouldn't this be
--------------------------
Now is: | After rounding
--------------------------
19:00 | 19:00*
19:05 | 19:15
19:12 | 19:15
19:16 | 19:30
19:30 | 19:30*
19:36 | 19:45
19:45 | 19:45*
20:00 | 20:00*


How about:

SELECT tblTimes.SomeTime,
DateAdd("n",15*(Minute([SomeTime])\15),DateAdd("h",Hour([sometime]),CDate(Int([sometime]))))
AS RoundedDateTime
FROM tblTimes;
I know, I know. Ugly. Yeah, but it does work!
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christopher T King | last post by:
Speakign of rounding errors, why is round() defined to round away from zero? I've always been quite fond of the mathematical definition of rounding of floor(n+.5). As a contrived example of why the...
6
by: DaveK | last post by:
I am upgrading an MS Access 97 application which uses the format function to round decimal numbers to two places e.g. format(dblValue, "standard") Having done an initial study of this...
13
by: dhildebrandt | last post by:
I have a query that uses the Round function to change decimals into whole numbers. For 4 years straight the thing has always rounded the numbers in exactly the same way so that whenever I update...
11
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...
5
by: Marcus | last post by:
Hi, was wondering if anyone knows a good algo for rounding time to a desired interval. For instance, I have data set that is timestamped in second resolution and I need to modify that data to be...
6
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, I'm using the following on a form in my database: =(-Int(-Sum((IIf(=Yes,((*)+()), (((*)+)*1.06))*100))))/100 In this case, I want to calculate a total for an order. If...
18
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...
206
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) ...
20
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>
30
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.