| Author |
Topic  |
|
|
bekeer020
Starting Member
USA
24 Posts |
Posted - 06/11/2012 : 15:25:12
|
Dear all
I have column with nvarchar datatype and the values like this
10:20 AM 2:31 PM
i want to compare this values with current time
Can any one help me .... |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 06/11/2012 : 16:58:28
|
use cast() to cast it to time datatype and compare
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
shilpash
Yak Posting Veteran
72 Posts |
Posted - 06/11/2012 : 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
USA
24 Posts |
Posted - 06/11/2012 : 17:44:28
|
Thanks all i 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 datetime declare @dEnd_Time datetime declare @Result nvarchar(50)
set @dStart_Time=(select cast(@Start_Time as datetime)) set @dEnd_Time=(select cast(@End_Time as datetime))
--select @mas1 , @mas2 if (dbo.gettimenow()>=@dStart_Time) and (dbo.gettimenow()<=@dEnd_Time)
set @Result='yes'
return @Result END |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 06/12/2012 : 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 MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|