By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,139 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,139 IT Pros & Developers. It's quick & easy.

Rounding time

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.