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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Validate Time

Author  Topic 

SD_Monkey
Starting Member

38 Posts

Posted - 2010-07-20 : 06:42:58
Can i lesser this User defined function
i need to validate the time if the hour is < 8:16 it will return a value of '8:00 AM' otherwise same value of 8:16 will be return??


DECLARE @rtime DATETIME
DECLARE @rvalue DATETIME
IF DATEPART(hh,@rtime) <= 8
BEGIN
IF DATEPART(hh,@rtime) = 8
BEGIN
IF DATEPART(mi,@rtime) < 16
BEGIN
SET @rvalue = CAST('8:00 AM' AS DATETIME)
END
ELSE
BEGIN
SET @rvalue = @rtime
END
END
ELSE
BEGIN
SET @rvalue = @rtime
END
END
RETURN @rvalue


A maze make you much more better

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-07-20 : 08:19:47
DECLARE @input DATETIME
DECLARE @compare datetime
set @input = '20100720 08:20'
set @compare = dateadd(day,datediff(day,0,@input),0)
SELECT case when datediff(mi,@compare,@input) < ( (8*60)+16) THEN dateadd(mi,(8*60),@compare) ELSE @input END

Jim
you'll want to change this ( (8*60)+16) I just did that for clarity.



Everyday I learn something that somebody else already knew
Go to Top of Page

SD_Monkey
Starting Member

38 Posts

Posted - 2010-07-20 : 08:24:05
tnx a lot...

A maze make you much more better
Go to Top of Page
   

- Advertisement -