I have a timeclock table with a timein and a timeout field, and I am using the following function(s) to return the time duration between timein and timeout, and display it in hours and minutes:
CONVERT(CHAR(5), DATEADD(SECOND, DATEDIFF(SECOND, TimeIn, TimeOut), 0), 108)
Here's what I need to do:
Round the minutes in the duration to the nearest 1/10th of an hour, or in other words, the neareast 6 minute increment (6, 12, 18, 24, 30, 36, 42, 48, 54, or 60 minutes)
UNLESS the minutes in the duration is closer to a 15 minute increment (15, 30, 45, or 60), in which case I need to round it to the nearest 15 minute increment instead.
For example here is a list of timein and timeout values, the actual duration between them, and what I need the rounded duration to be:
recordnbr | timein | timeout | duration | roundedduration
1 | 2008-10-09 07:45:00.000 | 2008-10-09 08:45:00.000 | 01:00 | 01:00
2 | 2008-10-09 07:45:00.000 | 2008-10-09 08:50:00.000 | 01:05 | 01:06
3 | 2008-10-09 07:45:00.000 | 2008-10-09 08:55:00.000 | 01:10 | 01:12
4 | 2008-10-09 07:45:00.000 | 2008-10-09 09:00:00.000 | 01:15 | 01:15
5 | 2008-10-09 07:45:00.000 | 2008-10-09 09:05:00.000 | 01:20 | 01:18
6 | 2008-10-09 07:45:00.000 | 2008-10-09 09:10:00.000 | 01:25 | 01:24
7 | 2008-10-09 07:45:00.000 | 2008-10-09 09:15:00.000 | 01:30 | 01:30
8 | 2008-10-09 07:45:00.000 | 2008-10-09 09:20:00.000 | 01:35 | 01:36
9 | 2008-10-09 07:45:00.000 | 2008-10-09 09:25:00.000 | 01:40 | 01:42
10 | 2008-10-09 07:45:00.000 | 2008-10-09 09:30:00.000 | 01:45 | 01:45
11 | 2008-10-09 07:45:00.000 | 2008-10-09 09:35:00.000 | 01:50 | 01:48
12 | 2008-10-09 07:45:00.000 | 2008-10-09 09:40:00.000 | 01:55 | 01:54
13 | 2008-10-09 07:45:00.000 | 2008-10-09 09:45:00.000 | 02:00 | 02:00
Note that in record number 4, where the duration is 1:15, it is not rounding up or down to 1:12 or 1:18, also not the same with record number 10, duration of 1:45, it is not rounded to 1:42 or 1:48.
Is this possible and if so how do I do this?? Please let me know if I need to supply any more information or explanation.
Thank you for your help,
Kevin
CONVERT(CHAR(5), DATEADD(SECOND, DATEDIFF(SECOND, TimeIn, TimeOut), 0), 108)
Here's what I need to do:
Round the minutes in the duration to the nearest 1/10th of an hour, or in other words, the neareast 6 minute increment (6, 12, 18, 24, 30, 36, 42, 48, 54, or 60 minutes)
UNLESS the minutes in the duration is closer to a 15 minute increment (15, 30, 45, or 60), in which case I need to round it to the nearest 15 minute increment instead.
For example here is a list of timein and timeout values, the actual duration between them, and what I need the rounded duration to be:
recordnbr | timein | timeout | duration | roundedduration
1 | 2008-10-09 07:45:00.000 | 2008-10-09 08:45:00.000 | 01:00 | 01:00
2 | 2008-10-09 07:45:00.000 | 2008-10-09 08:50:00.000 | 01:05 | 01:06
3 | 2008-10-09 07:45:00.000 | 2008-10-09 08:55:00.000 | 01:10 | 01:12
4 | 2008-10-09 07:45:00.000 | 2008-10-09 09:00:00.000 | 01:15 | 01:15
5 | 2008-10-09 07:45:00.000 | 2008-10-09 09:05:00.000 | 01:20 | 01:18
6 | 2008-10-09 07:45:00.000 | 2008-10-09 09:10:00.000 | 01:25 | 01:24
7 | 2008-10-09 07:45:00.000 | 2008-10-09 09:15:00.000 | 01:30 | 01:30
8 | 2008-10-09 07:45:00.000 | 2008-10-09 09:20:00.000 | 01:35 | 01:36
9 | 2008-10-09 07:45:00.000 | 2008-10-09 09:25:00.000 | 01:40 | 01:42
10 | 2008-10-09 07:45:00.000 | 2008-10-09 09:30:00.000 | 01:45 | 01:45
11 | 2008-10-09 07:45:00.000 | 2008-10-09 09:35:00.000 | 01:50 | 01:48
12 | 2008-10-09 07:45:00.000 | 2008-10-09 09:40:00.000 | 01:55 | 01:54
13 | 2008-10-09 07:45:00.000 | 2008-10-09 09:45:00.000 | 02:00 | 02:00
Note that in record number 4, where the duration is 1:15, it is not rounding up or down to 1:12 or 1:18, also not the same with record number 10, duration of 1:45, it is not rounded to 1:42 or 1:48.
Is this possible and if so how do I do this?? Please let me know if I need to supply any more information or explanation.
Thank you for your help,
Kevin