Groups | Blog | Home
all groups > sql server data mining > march 2004 >

sql server data mining : Problem converting to a date...


Atley
3/25/2004 10:47:41 AM
I have a field in a table that contains date data in the following format:

20040301

what is the best, low impact method for converting this to a useable date
field?


Tom Moreau
3/25/2004 10:56:24 AM
Try:

select
convert (datetime, '20040301', 112)

--
Tom

---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql


[quoted text, click to view]
I have a field in a table that contains date data in the following format:

20040301

what is the best, low impact method for converting this to a useable date
Adam Machanic
3/25/2004 10:57:46 AM
Populate a datetime column with the data...

ALTER TABLE YourTable ADD YourDatetimeCol DATETIME
GO

UPDATE YourTable SET YourDateTimeCol=CONVERT(DATETIME, YourNonDateTimeCol)
GO

Optionally, remove the old column, make the new column non-nullable, etc...


[quoted text, click to view]

Vishal Parkar
3/25/2004 9:33:28 PM
hi atley,

if the format of datetime string is yyyymmdd then just run following query:

select convert(datetime,'20040301') dt

--
Vishal Parkar
vgparkar@yahoo.co.in

Hari Prasad
3/25/2004 9:43:22 PM
Hi,

Have a look into the below code,

declare @col1 varchar(20)
declare @dt datetime
set @col1 ='20040301'
select @dt=convert(datetime,@col1)
select @dt

Tahnks
Hari
MCDBA

[quoted text, click to view]

AddThis Social Bookmark Button