Wednesday, September 21, 2011

MS SQL 2005: varchar to datetime - La conversión del tipo de datos varchar en datetime produjo un valor fuera de intervalo error.

I was trying to execute this:

update d_entrada set fecha_radicado = cast('2011-09-21 20:41:06.000' as datetime)  where id = '123456';


and I got this error

La conversión del tipo de datos varchar en datetime produjo un valor fuera de intervalo error.

I put the datetime this way ('2011-09-21 20:41:06.000') because when I execute

select fecha_radicado from d_entrada where id = '123456';

I get

2011-09-21 20:41:06.000

But to make the update query work propertly I had to switch 09 and 21 date values:

update d_entrada set fecha_radicado = cast('2011-21-09 20:41:06.000' as datetime)  where id = '123456';


then I got:



(1 row(s) affected)


No comments: