August 12, 2015 at 8:08 am
Hi
I am getting the time difference between two dates using
DATEDIFF(second,Information.[Start Time],Information.[End Time]) / 60.00 / 60.00 AS hours,
My output looks like
1.33
0.17
1.50
etc
I'd like to round to the nearest quarter hour
1.50
0.25
.150
etc
Thanks
August 12, 2015 at 8:20 am
Do you always want to round up? Or why isn't the first result 1.25?
August 12, 2015 at 8:25 am
Yes sorry , bad example, I am looking to round up to the nearest 1/4 hour
August 12, 2015 at 8:25 am
An idea:
SELECT DATEDIFF(second,Information.[Start Time],Information.[End Time]) / 60.00 / 60.00,
CEILING( DATEDIFF(second,Information.[Start Time],Information.[End Time])*4 / 60.00 / 60.00) / 4 AS Rounded_Hours,
ROUND( DATEDIFF(second,Information.[Start Time],Information.[End Time])*4 / 60.00 / 60.00, 0) / 4 AS Rounded_Up_Hours,
ROUND( DATEDIFF(second,Information.[Start Time],Information.[End Time])*4 / 60.00 / 60.00, 0, 1) / 4 AS Rounded_Down_Hours
FROM (VALUES( CAST( '05:30' as time), CAST( '06:50' as time)),
( CAST( '07:20' as time), CAST( '07:30:20' as time)),
( CAST( '12:00' as time), CAST( '13:30' as time)) ) Information([Start Time],[End Time])
August 12, 2015 at 8:34 am
CEILING( DATEDIFF(second,Information.[Start Time],Information.[End Time])*4 / 60.00 / 60.00) / 4 AS Rounded_Hours,
Works as I needed , and I now have other options in my libray
Thanks so much!!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply