Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hot convert string to datetime

Status
Not open for further replies.

room24

Programmer
Dec 28, 2003
83
JM
'1182004'
@result_date has in the above string value

i am trying to convert it using convert(datetime, @result_date)

but i get this errror
Syntax error converting datetime from character string.
 
Is it Jan 18th 2004? or Aug 11th 2004? Place leading zero so that both day and month occupy 2 characters.

CONVERT() also has 3rd optional parametar (date format style), though I'm not sure ddmmyy is supported.

 
You will need to do some string manipultaion to get this to work.

declare @result_date varchar(100)
set @result_date = '1182004'
set @result_date = stuff(@result_date,4,0,'-')
set @result_date = stuff(@result_date,2,0,'-')
select CONVERT(DATETIME, @result_date)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top