On 22 Nov 2006 22:46:19 -0800, paul_zaoldyeck wrote:
>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