August 5, 2012 at 1:54 am
Does anyone know how to convert varchar datatype to datetime in TSQL?
August 5, 2012 at 6:59 am
CAST and CONVERT (Transact-SQL)
Is there any problem with that?
August 5, 2012 at 7:07 am
leonie6214 (8/5/2012)
Does anyone know how to convert varchar datatype to datetime in TSQL?
please give example of what you want to convert
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
August 5, 2012 at 7:39 am
As previously stated you can use CAST or CONVERT. But like many items in T-SQL "It depends". As an example ... be aware of your system date format, and of course the format of the actual data.
DECLARE @T VARCHAR(40)
SET DATEFORMAT dmy
SET @T = '2012-08-05 09:13:50.053'
SELECT CAST(@T AS DATETIME)
SET @T = '20120805 09:13:50.053'
SELECT CAST(@T AS DATETIME)
Results:
2012-05-08 09:13:50.053
2012-08-05 09:13:50.053
As is obvious the results are dramatically different. If you would post a sample of your actual data, and your systems dateformat someone may be able to assist you furter.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply