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-11 : 15:25:12
|
Dear allI have column with nvarchar datatypeand the values like this10:20 AM2:31 PMi want to compare this values with current timeCan any one help me .... |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-11 : 16:58:28
|
use cast() to cast it to time datatype and compare------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
shilpash
Posting Yak Master
103 Posts |
Posted - 2012-06-11 : 17:01:59
|
CREATE TABLE #abc(tt NVARCHAR(20))INSERT INTO #abc (tt) VALUES ('10:20 AM' )SELECT DATEDIFF (hh,convert(varchar(5),tt,8),convert(varchar(5),getdate(),8)) AS hours,DATEDIFF (mi,convert(varchar(5),tt,8),convert(varchar(5),getdate(),8)) AS mins FROM #abc |
|
|
bekeer020
Starting Member
24 Posts |
Posted - 2012-06-11 : 17:44:28
|
Thanks alli try to use cast then solved=====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))--select @mas1 , @mas2if (dbo.gettimenow()>=@dStart_Time) and (dbo.gettimenow()<=@dEnd_Time)set @Result='yes'return @ResultEND |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-12 : 15:17:15
|
Casting it to datetime causes datepart to be appended with base date value of 19000101. Hope you're aware of that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|