here is the situation
J_TIM < F_TIM
J_TIM is datetime while F_TIM is char of 4
example
J_TIM = 20:30
F_TIM = 2030
how can i convert F_TIM to datetime so that i can compare them.
?
thanksYou can try something like:
select *
from sometable
where convert(datetime, '20060101 ' + J_TIM) <
convert(datetime,'20060101 ' + substring(F_TIM,1,2) + ':' +
substring(F_TIM,3,2))
paul_zaoldyeck wrote:
Quote:
Originally Posted by
i have another problem.and it's now on converting a char(4) to datetime
here is the situation
J_TIM < F_TIM
>
J_TIM is datetime while F_TIM is char of 4
>
example
>
J_TIM = 20:30
F_TIM = 2030
>
how can i convert F_TIM to datetime so that i can compare them.
?
>
thanks
Quote:
Originally Posted by
>i have another problem.and it's now on converting a char(4) to datetime
>here is the situation
>J_TIM < F_TIM
>
>J_TIM is datetime while F_TIM is char of 4
>
>example
>
>J_TIM = 20:30
>F_TIM = 2030
>
>how can i convert F_TIM to datetime so that i can compare them.
>?
>
>thanks
Hi Paul,
DECLARE @.F_TIM char(4);
SET @.F_TIM = '2030';
SELECT STUFF(@.F_TIM, 3, 0, ':');
SELECT CAST(STUFF(@.F_TIM, 3, 0, ':') AS datetime);
Note that the reply posted by othellomy will work, but won't enable you
to efficiently use an index on the J_TIM column (in case there is one).
Also read Tibor's ultimate guide to the datetime datatype. You'll find
it at http://www.karaszi.com/SQLServer/info_datetime.asp
--
Hugo Kornelis, SQL Server MVP|||thanks for the codes...they all worked out...
regards!!!
Hugo Kornelis wrote:
Quote:
Originally Posted by
On 22 Nov 2006 22:46:19 -0800, paul_zaoldyeck wrote:
>
Quote:
Originally Posted by
i have another problem.and it's now on converting a char(4) to datetime
here is the situation
J_TIM < F_TIM
J_TIM is datetime while F_TIM is char of 4
example
J_TIM = 20:30
F_TIM = 2030
how can i convert F_TIM to datetime so that i can compare them.
?
thanks
>
Hi Paul,
>
DECLARE @.F_TIM char(4);
SET @.F_TIM = '2030';
SELECT STUFF(@.F_TIM, 3, 0, ':');
SELECT CAST(STUFF(@.F_TIM, 3, 0, ':') AS datetime);
>
Note that the reply posted by othellomy will work, but won't enable you
to efficiently use an index on the J_TIM column (in case there is one).
>
Also read Tibor's ultimate guide to the datetime datatype. You'll find
it at http://www.karaszi.com/SQLServer/info_datetime.asp
>
--
Hugo Kornelis, SQL Server MVP
No comments:
Post a Comment