Monday, March 19, 2012

Convert varchar to datetime

I have a column that holds dates but is varchar(50) and contains data in the following format:

01/12/2003

Code:
SET DATEFORMAT dmy
DECLARE @.Data DATETIME
SET @.Data = 01/01/2004
SELECT * FROM Lista WHERE CONVERT(DATETIME, Data) < @.Data

With this code it does not return no result. But if to change the operator returns all the registers. E all the registered in cadastre dates are 1/1/2003

Help me please.Hi there,

instead of
SET @.Data = 01/01/2004
you should try
SET @.Data = '01/01/2004'
and it should work!

Greetings,
Carsten|||Very thanks!
You really it saved my day.
Thanks

No comments:

Post a Comment