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.
Author |
Topic |
bekeer020
Starting Member
24 Posts |
Posted - 2012-06-24 : 06:41:04
|
Dear allI have table with columns nvarchatr "Start_TIme,End_TIme"I want to create function to compare if cuurent time between Start_Time and End_Time return "Yes" for examplehow can i do like thisthis is my example but not working=========================ALTER function [dbo].[check_class_now](@Start_Time nvarchar(50),@End_Time nvarchar(50))returns nvarchar(50)as begin declare @dStart_Time datetimedeclare @dEnd_Time datetimedeclare @Result nvarchar(50) set @dStart_Time=(select cast(@Start_Time as datetime))set @dEnd_Time=(select cast(@End_Time as datetime)) if (dbo.gettimenow()>=@dStart_Time) and (dbo.gettimenow()<=@dEnd_Time) set @Result='yes' return @ResultEND=============================ALTER function [dbo].[gettimenow]()returns nvarchar(20)as begin Declare @result nvarchar(20)set @result= (SELECT SUBSTRING(CONVERT(varchar, GETDATE(), 100), 13, 2) + ':' + SUBSTRING(CONVERT(varchar, GETDATE(), 100), 16, 2) + ' ' + SUBSTRING(CONVERT(varchar, GETDATE(), 100), 18, 2) AS MyTime)return @resultend=====Note : mt time formate 12 hourse like (1:44 PM ) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-24 : 13:09:59
|
make function likeALTER function [dbo].[check_class_now](@Start_Time datetime,@End_Time datetime)returns bitas begin declare @Result bitset @Result=CASE WHEN DATEADD(dd,-1 * DATEDIFF(dd,0,GETDATE()),GETDATE()) BETWEEN CONVERT(datetime,@Start_Time) AND CONVERT(datetime,@End_Time) THEN 1 ELSE 0 ENDreturn @ResultENDthen call it like SELECT dbo.[check_class_now] (starttime,endtime),...FROM Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bekeer020
Starting Member
24 Posts |
Posted - 2012-06-24 : 18:27:53
|
Done thank you visakh16 |
|
|
|
|
|
|
|