Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 round to near value

Author  Topic 

born2acheive
Yak Posting Veteran

65 Posts

Posted - 2007-01-04 : 00:45:33
hi,i have one criteria

if if i have time as 1:15 min means it has to show 1:15,if i have 1:20 min it has too be rounded and it has to show 1:30 min.
can any one give me query for this
thanks in anvance

born2acheive
Yak Posting Veteran

65 Posts

Posted - 2007-01-04 : 01:32:05
please can any one reply me
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-04 : 02:52:08
Use this function by MVJ to get your time at any time interval.
create function dbo.F_START_OF_X_MIN
( @DAY datetime, @INTERVAL SMALLINT )
returns datetime
as
begin

declare @BASE_DAY datetime
select @BASE_DAY = dateadd(dd,datediff(dd,0,@Day),0)

return dateadd(mi,(datediff(mi,@BASE_DAY,@Day)/@INTERVAL)*@INTERVAL,@BASE_DAY)

end
Call with

SELECT dbo.F_START_OF_X_MIN('1:15', 15)
SELECT dbo.F_START_OF_X_MIN('1:35', 15)

This function rounds backwards for the time interval given.
You can easily alter the function to round forwards.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

born2acheive
Yak Posting Veteran

65 Posts

Posted - 2007-01-04 : 03:07:48
hi peso thanks a lot
Go to Top of Page
   

- Advertisement -